【发布时间】:2021-02-24 20:38:44
【问题描述】:
如何使用 BeautifulSoup 从网页中获取链接,将它们存储在列表中,然后打印出某个链接? 这是我目前所拥有的:
from urllib.request import urlopen
from bs4 import BeautifulSoup
html = urlopen("https://example.com/")
content = BeautifulSoup(html.read(), "html.parser")
for link in content.find_all("a"):
print(link.get("href")[0])
但我收到此错误:
TypeError: 'NoneType' object is not subscriptable如何解决这个问题并获得第一个链接?
【问题讨论】:
标签: python python-3.x list web-scraping