我在 Windows XP 上使用 Python 2.7.3 我正在使用 Pyscripter 2.5.3.0
我正在尝试运行漂亮的汤并使用以下测试代码
import urllib2
from bs4 import BeautifulSoup
page = urllib2.urlopen("http://www.google.com")
soup = BeautifulSoup(page)
print soup.prettify()
代码停在dammit.py
. 错误是:
Message File Name Line Position
Traceback
<module> D:\Python\TestBS.py 19
<module> C:\Python27\lib\site-packages\bs4\__init__.py 29
<module> C:\Python27\lib\site-packages\bs4\builder\__init__.py 4
<module> C:\Python27\lib\site-packages\bs4\element.py 5
<module> C:\Python27\lib\site-packages\bs4\dammit.py 49
EntitySubstitution C:\Python27\lib\site-packages\bs4\dammit.py 70
_populate_class_variables C:\Python27\lib\site-packages\bs4\dammit.py 57
NameError: global name 'codepoint2name' is not defined
在这部分代码上
class EntitySubstitution(object):
"""Substitute XML or HTML entities for the corresponding characters."""
def _populate_class_variables():
lookup = {}
reverse_lookup = {}
characters_for_re = []
for codepoint, name in list(codepoint2name.items()):