【问题标题】:Python3.6 BeautifulSoup is not workingPython3.6 BeautifulSoup 不工作
【发布时间】:2017-08-11 16:34:45
【问题描述】:

我的代码如下;

source_code = requests.get(kale_url_keys)
plain_text = source_code.text
soup = BeautifulSoup("plain_text ")

r = requests.get(kale_url_keys)
html = r.content
soup = BeautifulSoup(html, "html.parser")

我在写下面这样的“soup = BeautifulSoup(ANYTHING)”时出错了;

【问题讨论】:

  • 我看到你有 Python 3.6。 beautifulsoup4 更新到最新版本了吗?
  • Python 3.6。是的,我更新了 beautifulsoup4。
  • 我无法用全新的 Win7 @ amd64 安装和 Python 3.6.0 重现它:(
  • 请使用python --version 的输出更新您的答案。更新:您似乎必须将requestsurllib3 更新到最新版本。你可以用pip来做。
  • Python 3.6.1rc1 。我已经更新了请求,bs4。

标签: python python-3.x web-scraping beautifulsoup html-table


【解决方案1】:

做两件事:

  • 安装最新的稳定版 Python 3.6.0
  • 更新beautifulsoup4 - 确保在正确的 Python 3.6.0 环境中更新它:

    pip3 install beautifulsoup4 --upgrade
    

【讨论】:

  • 我删除了所有 python 版本,然后我设置了 Python 3.6.0,然后我加载了所有库。它的工作原理。谢谢
【解决方案2】:

尝试使用 request.urlopen 而不是 html.parser lxml 我和你在同一个版本的python上,一切正常。似乎您从 html.parser 收到错误,因此使用 lxml 解析器应该可以工作

pip install lxml

Here for Linux or other installation methods. 用法:soup = BeautifulSoup(html, "lxml")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-17
    • 2017-08-06
    • 2020-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多