首页 > 解决方案 > BeautifulSoup find_all() 正在返回空列表

问题描述

我对编程很陌生。目前,我正在通过 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”字符。但是,当我想运行此代码时,它返回一个空列表:

输出:

[]

我该如何解决这个问题?谢谢您的回答。

标签: pythonbeautifulsoup

解决方案


也许您正在解析的网址上没有链接,我尝试过一个有网址的链接,它工作正常

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"))

推荐阅读