在Windows中解析包含BeautifulSoup4、Chardet和Python 3.3的页面时出错
当我尝试调用BeautifulSoup(第页)时,出现以下错误在Windows中解析包含BeautifulSoup4、Chardet和Python 3.3的页面时出错,python,html,windows,beautifulsoup,chardet,Python,Html,Windows,Beautifulsoup,Chardet,当我尝试调用BeautifulSoup(第页)时,出现以下错误 我期待您的回答我刚刚遇到这种情况。 不要导入chardet,我也会卸载chardet。 然后构建就会通过 下面的代码是beautifulsoup中的dammit.pylib的一部分。 可能您导入的chardet不适合Python3.3,因此会发生错误 try: # First try the fast C implementation. # PyPI package: cchardet import cch
我期待您的回答我刚刚遇到这种情况。
不要导入chardet,我也会卸载chardet。
然后构建就会通过
下面的代码是beautifulsoup中的
dammit.py
lib的一部分。可能您导入的chardet不适合Python3.3,因此会发生错误
try:
# First try the fast C implementation.
# PyPI package: cchardet
import cchardet
def chardet_dammit(s):
return cchardet.detect(s)['encoding']
except ImportError:
try:
# Fall back to the pure Python implementation
# Debian package: python-chardet
# PyPI package: chardet
import chardet
def chardet_dammit(s):
return chardet.detect(s)['encoding']
#import chardet.constants
#chardet.constants._debug = 1
except ImportError:
# No chardet available.
def chardet_dammit(s):
return None
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)
try:
# First try the fast C implementation.
# PyPI package: cchardet
import cchardet
def chardet_dammit(s):
return cchardet.detect(s)['encoding']
except ImportError:
try:
# Fall back to the pure Python implementation
# Debian package: python-chardet
# PyPI package: chardet
import chardet
def chardet_dammit(s):
return chardet.detect(s)['encoding']
#import chardet.constants
#chardet.constants._debug = 1
except ImportError:
# No chardet available.
def chardet_dammit(s):
return None