python - 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”字符。但是,当我想运行此代码时,它返回一个空列表:
输出:
[]
我该如何解决这个问题?谢谢您的回答。
解决方案
也许您正在解析的网址上没有链接,我尝试过一个有网址的链接,它工作正常
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"))
推荐阅读
- javascript - EJS 模板中的 setInterval() 不起作用
- django - Django搜索栏没有进入正确的页面
- python - HoughCircles 无法检测到这个圈子
- php - 如何在 Laravel 中按 ID 删除子文件夹?
- swift - 如何将一个pickerview用于多个文本字段?
- raspberry-pi - 从 can bus 读取消息并显示在树莓派网页上
- asp.net-core - 如何从 Blazor 的数据库中获取经过身份验证的用户
- javascript - 如何在 React State 中更新 Array 的奇异值
- javascript - Javascript 反引号字符串插值创建带有空格的 URL
- javascript - 无法写入 javascript 回调中的 textContent 属性