渊博自习室 2022-10-31 17:47 采纳率: 0%
浏览 3

find_all错误原因

import requests
from bs4 import BeautifulSoup
URL = "https://bbs.bccn.net/search.php?searchid=1%20&%20searchsubmit=yes%22
headers = {"cookie":"bbs1_sid=HkmS8P; bbs1_referer=/"}
r = requests.get(URL, headers=headers)
if "您还没有登陆" not in r.text:
soup = BeautifulSoup(r.text, "lxml")
table_search = soup.find("table", summary="搜索")
tag_a = table_search.find_all("a", target="_black")
for tag in tag_a:
print(tag.text)
else:
print("未登陆,请检查Cookie")

Traceback (most recent call last):
File "/Users/mac/PycharmProjects/pythonProject2/Ch7_1d.py", line 9, in
tag_a = table_search.find_all("a", target="_black")
AttributeError: 'NoneType' object has no attribute 'find_all'

  • 写回答

2条回答 默认 最新

  • honestman_ 2022-10-31 18:36
    关注

    table_search = soup.find("table", summary="搜索")
    这一行有问题,没有找到这个搜索的table,检查一下页面

    评论

报告相同问题?

问题事件

  • 创建了问题 10月31日