簡體   English   中英

BeautifulSoup find_all() 正在返回空列表

[英]BeautifulSoup find_all() is returning empty list

我對編程很陌生。 目前,我正在通過 Udemy 課程學習 Python。 我正在使用 Windows 10 操作系統,我正在使用帶有 Anaconda 解釋器的 VS Code:這里是


import requests
from bs4 import BeautifulSoup

url = "https://yellowpages.com.tr/ara?q=ankara"

response = requests.get(url)

html_content = response.content

soup = BeautifulSoup(html_content, "html.parser")

print(soup.find_all("a"))

我編寫了這段代碼來吸引網站中的所有“a”字符。 但是,當我想運行此代碼時,它返回一個空列表:

output:

[]

我該如何解決這個問題? 謝謝您的回答。

也許您正在解析的 url 沒有鏈接,我嘗試過一個有網址的鏈接,它工作正常

import requests
from bs4 import BeautifulSoup

url = "https://cloud.google.com/solutions/media-entertainment/optimizing-audio-files-for-speech-to-text?hl=it"
response = requests.get(url)
html_content = response.content

soup = BeautifulSoup(html_content, "html.parser")

print(soup.find_all("a"))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM