【问题标题】:Beautifulsoup4 problemsBeautifulsoup4 问题
【发布时间】:2020-06-09 19:01:52
【问题描述】:

python 新手并尝试进行基本的网络抓取。我的代码与错误消息一起在下面。我花了好几个小时才弄清楚为什么当我把它从互联网上拉下来时会出错。任何帮助将不胜感激。

import requests
from bs4 import BeautifulSoup

page = requests.get('https://forecast.weather.gov/MapClick.php?lat=33.93680995224785&lon=-118.24891999999994#.Xt_LOzpKiUk')

soup = BeautifulSoup(page.text, 'html.parser')
print(soup)

文件 "C:\Users\mariomanfredi\Anaconda\newupload\lib\site-packages\bs4\builder_htmlparser.py", 第 325 行,在 init 中 super(HTMLParserTreeBuilder, self).init(**kwargs)

TypeError: super(type, obj): obj must be an instance or subtype of 输入

【问题讨论】:

  • 在我的机器上运行良好,您的依赖项安装正确吗?
  • 更新您的 bs4 和请求,您使用的是什么 python 版本?

标签: python beautifulsoup


【解决方案1】:

我尝试了与您在我的机器上发布的完全相同的代码,它似乎工作正常。您确定已正确安装所有必需的依赖项吗?

如果仍然无法正常工作,请尝试使用其他解析器,例如 lxml。你可以使用pip install lxml安装它

lxml 通常也更快。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-25
    • 2021-02-19
    • 2014-09-16
    • 2012-09-19
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    • 2021-08-28
    相关资源
    最近更新 更多