I am having a strange error using BeautifulSoup.
Here is a snippet of the code I am running:
while True:
listing_soup = soupify(urlget(page_url))
for i in listing_soup.findAll('div', 'searchResultContent'):
# do some stuff ...
Here is the exception being thrown:
Traceback (most recent call last):
File "C:\path\to\script.py", line 71
6, in <module>
for i in listing_soup.findAll('div', 'searchResultContent'):
File "c:\python27\BeautifulSoup.py", line 612, in findAll
return self._findAll(name, attrs, text, limit, generator, **kwargs)
File "c:\python27\BeautifulSoup.py", line 275, in _findAll
strainer = SoupStrainer(name, attrs, text, **kwargs)
File "c:\python27\BeautifulSoup.py", line 660, in __init__
self.attrs=attrs.copy()
AttributeError: 'str' object has no attribute 'copy'
I am running Python 2.7.3 on Windows XP Professional. This script worls fine on Ubuntu Linux.
Note:
I am expecting the data from the web to be UTF, so the python script starts with the following line:
# coding=utf-8
Judging from the line numbers, you’re using Beautiful Soup 3.0.0, which doesn’t have the “search by CSS class” shortcut you’re trying to use (it was reintroduced in 3.0.1). More to the point, you’re using a version of the software that’s five years old. I recommend Beautiful Soup 4 for all new projects.
Most likely you don’t see the problem on Ubuntu because your Ubuntu installation is running a more recent version of Beautiful Soup.