BeautifulSoup import error
1011_wxy
1011_wxy at 163.com
Thu May 5 21:37:38 EDT 2011
Dear friends:
I got a import error when I use Python 3.2 to import BeautifulSoup 3.2.0 .
Is there any differences between Python 3.2 and other version? This is my first time to use Python3.2 .
And the error message will be as below.
>>> from BeautifulSoup import BeautifulSoup
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
from BeautifulSoup import BeautifulSoup
File "C:\Python32\BeautifulSoup.py", line 448
raise AttributeError, "'%s' object has no attribute '%s'" % (self.__class__.__name__, attr)
^
SyntaxError: invalid syntax
And the error place point to BeautifulSoup
class NavigableString(unicode, PageElement):
def __new__(cls, value):
"""Create a new NavigableString.
When unpickling a NavigableString, this method is called with
the string in DEFAULT_OUTPUT_ENCODING. That encoding needs to be
passed in to the superclass's __new__ or the superclass won't know
how to handle non-ASCII characters.
"""
if isinstance(value, unicode):
return unicode.__new__(cls, value)
return unicode.__new__(cls, value, DEFAULT_OUTPUT_ENCODING)
def __getnewargs__(self):
return (NavigableString.__str__(self),)
def __getattr__(self, attr):
"""text.string gives you text. This is for backwards
compatibility for Navigable*String, but for CData* it lets you
get the string without the CData wrapper."""
if attr == 'string':
return self
else:
raise AttributeError, "'%s' object has no attribute '%s'" % (self.__class__.__name__, attr)
def __unicode__(self):
return str(self).decode(DEFAULT_OUTPUT_ENCODING)
def __str__(self, encoding=DEFAULT_OUTPUT_ENCODING):
if encoding:
return self.encode(encoding)
else:
return self
Did I make any mistake?
How can I do this correctly?
2011-05-06
Kerry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110506/9ab0a410/attachment.html>
More information about the Python-list
mailing list