Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #4788
| Date | 2011-05-06 09:37 +0800 |
|---|---|
| From | "1011_wxy"<1011_wxy@163.com> |
| Subject | BeautifulSoup import error |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1213.1304645692.9059.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
BeautifulSoup import error "1011_wxy"<1011_wxy@163.com> - 2011-05-06 09:37 +0800
csiph-web