当我尝试调用 BeautifulSoup(page) 时出现以下错误
Traceback (most recent call last):
File "error.py", line 10, in <module>
soup = BeautifulSoup(page)
File "C:\Python33\lib\site-packages\bs4\__init__.py", line 169, in __init__
self.builder.prepare_markup(markup, from_encoding))
File "C:\Python33\lib\site-packages\bs4\builder\_htmlparser.py", line 136, in
prepare_markup
dammit = UnicodeDammit(markup, try_encodings, is_html=True)
File "C:\Python33\lib\site-packages\bs4\dammit.py", line 223, in __init__
u = self._convert_from(chardet_dammit(self.markup))
File "C:\Python33\lib\site-packages\bs4\dammit.py", line 30, in chardet_dammit
return chardet.detect(s)['encoding']
File "C:\Python33\lib\site-packages\chardet\__init__.py", line 21, in detect
import universaldetector
ImportError: No module named 'universaldetector'
我在 Windows 7 中运行 Python 3.3,我通过下载 .tar.gz 从 setup.py 安装了 bs4。我已经安装了 pip,然后通过执行 pip.exe install chardet 安装了 chardet。我的 chardet 版本是 2.2.1。Bs4 适用于其他网址。
这是代码
import sys
from urllib.request import urlopen
from bs4 import BeautifulSoup
import re
import chardet
url = "http://www.edgar-online.com/brand/yahoo/search/?cik=1400810"
page = urlopen(url).read()
#print(page)
soup = BeautifulSoup(page)
我期待你的回答