【发布时间】:2021-06-01 10:39:28
【问题描述】:
当我将此代码运行到此页面 (https://www.baiscopelk.com/tv-series/dark) 时,它工作正常。为什么会发生这种情况
import requests
from bs4 import BeautifulSoup
page = requests.get("https://www.baiscopelk.com/tv-series/game-of-thrones/")
soup = BeautifulSoup(page.content, 'html.parser')
column = []
for tr in soup.find("table" , class_="aligncenter").find_all("tr") :
for links in tr.find_all('td')[0]:
try:
print(links.get("href"))
except:
print("error")
输出
error
None
None
None
None
None
None
https://www.baiscopelk.com/?p=15124
https://www.baiscopelk.com/?p=15614
https://www.baiscopelk.com/?p=16099
https://www.baiscopelk.com/?p=16524
https://www.baiscopelk.com/?p=17179
【问题讨论】:
-
因为
links.get("href")有时会返回None。 -
请不要在标题中添加标签,这是标签的作用。
标签: python beautifulsoup python-requests