BeautifulSoup find_all()返回空列表

时间:2020-08-06 19:08:46

标签: python beautifulsoup

我对编程很陌生。目前,我正在用Udemy课程学习Python。我正在使用Windows 10操作系统,并且在Anacodeda解释器中使用VS Code:Here it is


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”型人物。但是,当我要运行此代码时,它将返回一个空列表:

输出:

[]

如何解决此问题?谢谢您的回答。

1 个答案:

答案 0 :(得分:1)

也许您正在解析的url上没有链接,我已经尝试过使用一个具有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"))