gpt4 book ai didi

python - 使用BeautifulSoup python 时出错

转载 作者:行者123 更新时间:2023-12-01 05:08:28 26 4
gpt4 key购买 nike

我是 HTML 解析器的新手。我实际上正在尝试使用 url ( http://www.quora.com/How-many-internships-are-necessary-for-a-B-Tech-student ) 解析网页的源代码。我正在尝试获取answer_count。

我尝试了以下方法:

import urllib2
from bs4 import BeautifulSoup

q = urllib2.urlopen(url)
soup = BeautifulSoup(q)
divs = soup.find_all('div',class_='answer_count')

但是我得到的“divs”列表为空。为什么会这样呢?我哪里错了?我如何实现它以获得“2 个答案”的结果?

最佳答案

也许您的浏览器上没有与我们相同的页面(因为您已登录等)。

当我查看您通过 Google Chrome 提供的网页时,源代码中没有“answer_count”。因此,如果 Google chrome 找不到它,BeautifulSoup 也不会找到它

关于python - 使用BeautifulSoup python 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24648353/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com