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'