我使用Python 2.7.3在Windows XP 我使用Pyscripter 2.5.3.0NameError:全局名稱「codepoint2name」沒有定義
我試圖讓美麗的湯運行,使用下面的測試代碼
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()):
BeautifulSoup的哪個版本? – Blender
@Blender:從代碼示例和追蹤它似乎是版本4('bs4')。 –