当我运行这个代码到这个页面(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
这是因为有些
<td>
标记没有任何href
属性。寻找<a>
标记并解决这些问题会更好吗输出:
相关问题 更多 >
编程相关推荐