url = "https://www.cnn.com/"
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
links = []
for link in soup(response).find_all("a", href=True):
links.append(link["href"])
for link in links:
print(links)
AttributeError:ResultSet 物件沒有屬性“find_all”。您可能將元素串列視為單個元素。當您打算呼叫 find() 時,您是否呼叫了 find_all()?
我不太確定為什么會收到此錯誤,我正在嘗試從該網站上抓取所有 href / 鏈接。
uj5u.com熱心網友回復:
你不需要打電話soup(response),find_all直接打電話就可以了soup。Soup 已經有了第 5 行的回應資訊,所以它是多余的。
# Replace this:
for link in soup(response).find_all("a", href=True):
# With this
for link in soup.find_all("a", href=True):
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/532948.html
