鱼C论坛

 找回密码
 立即注册
查看: 1047|回复: 4

BeautifulSoup的使用问题

[复制链接]
发表于 2018-7-17 09:55:55 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#!user\bin\env  python
#-*-conding:UTF-8 -*-
# author zlz time: 2018.07.16
from bs4 import BeautifulSoup

html = """
<html><head><title>The Dormouse's story</title></head>
<body>
<p class="title" name="dromouse"><b>The Dormouse's story</b></p>
<p class="story">Once upon a time there were three little sisters; and their names were
<a href="http://example.com/elsie" class="sister" id="link1"><!-- Elsie --></a>,
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;
and they lived at the bottom of a well.</p>
<p class="story">...</p>
"""
soup = BeautifulSoup(html)
print(soup.prettify())

执行后出现如下:
D:\phython-64bit\python.exe D:/2/14.py
Traceback (most recent call last):
  File "D:/2/14.py", line 17, in <module>
    soup = BeautifulSoup(html)
  File "D:\phython-64bit\lib\bs4\__init__.py", line 168, in __init__
    self._feed()
  File "D:\phython-64bit\lib\bs4\__init__.py", line 181, in _feed
    self.builder.feed(self.markup)
  File "D:\phython-64bit\lib\bs4\builder\_htmlparser.py", line 131, in feed
    parser = BeautifulSoupHTMLParser(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'strict'

Process finished with exit code 1
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-7-17 10:04:06 | 显示全部楼层
soup = BeautifulSoup(html,'html.parser')
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-7-17 17:22:40 | 显示全部楼层
故梦L 发表于 2018-7-17 10:04
soup = BeautifulSoup(html,'html.parser')

D:\phython-64bit\python.exe D:/2/15.py
Traceback (most recent call last):
  File "D:/2/15.py", line 18, in <module>
    soup = BeautifulSoup(html,'html.parser')
  File "D:\phython-64bit\lib\bs4\__init__.py", line 168, in __init__
    self._feed()
  File "D:\phython-64bit\lib\bs4\__init__.py", line 181, in _feed
    self.builder.feed(self.markup)
  File "D:\phython-64bit\lib\bs4\builder\_htmlparser.py", line 131, in feed
    parser = BeautifulSoupHTMLParser(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'strict'

Process finished with exit code 1
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-7-18 09:55:04 | 显示全部楼层
故梦L 发表于 2018-7-17 10:04
soup = BeautifulSoup(html,'html.parser')

这个我试了,还是有问题啊
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-7-20 09:17:58 | 显示全部楼层
已解决,原因正如提示,解决办法是:1,python与第三方库(beautiful)版本匹配 2,安装lxml,html5lib的库;pycharm也是要重新安装库。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-12-31 19:32

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表