Python3.6 BeautifulSoup无效

时间:2017-03-20 11:54:00

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

我的代码如下;

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

我在撰写"汤= BeautifulSoup(ANYTHING)"时出错了。如下;

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:2)

做两件事:

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

    pip3 install beautifulsoup4 --upgrade
    

答案 1 :(得分:0)

尝试而不是使用request.urlopen而不是html.parser lxml 我和你一样使用相同版本的python,一切正常。好像你从html.parser得到错误所以使用lxml解析器应该可以工作

pip install lxml

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