how pickle.dumps a NavigableString in python 2.5

49 views
Skip to first unread message

HG

unread,
Aug 23, 2007, 4:19:25 AM8/23/07
to beautifulsoup
hi,All
when i pickle.dump s, which is instance of NavigableString, in
python2.4, occurs error
Traceback (most recent call
last):
File "beautiful_test.py", line 21,
in ?
print
pickle.dumps( s )
TypeError: 'NoneType' object is not callable

in python 2.5, the error:

Traceback (most recent call
last):
File "beautiful_test.py", line 21, in
<module>
print
pickle.dumps( s )
RuntimeError: maximum recursion depth exceeded

if i unicode(s) or str(s) , then dump s again, in 2.4 ,it works.
but in 2.5 ,the error remain :"RuntimeError: maximum recursion depth
exceeded"
how can i dumps the NavigableString in python 2.5?
thanks
HG
BTW, my demo code listed below:

from BeautifulSoup import BeautifulSoup
import re
import cPickle as pickle
doc = ['<html><head><title>Page title</title></head>',
'<body><p id="firstpara" align="center">This is paragraph
<b>one</b>.',
'<p id="secondpara" align="blah">This is paragraph <b>two</
b>.',
'<a href="http://www.google.com/down/sort/678/678_1.htm"
target="_blank"> &nbsp;asdf </a>',
'<a href="http://www.google.com/down/sort/678/678_1.htm"
target="_blank"> &nbsp;asdf<img src="asdfsdf" alt="image_alt"></a>\
',
'<OBJECT codeBase=http://download.macromedia.com/pub/shockwave/
cabs/flash/swflash.cab#version=5,0,0,0 height=398 width=500 \
classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000>
\
<PARAM NAME="quality" VALUE="high">
\
<PARAM NAME="SRC" VALUE="http://2.google.com/data/
4299games/smashing.swf">\
<EMBED QUALITY=high PLUGINSPAGE="http://
www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFl\
ash" TYPE="application/x-shockwave-flash" WIDTH="500" HEIGHT="398"
SRC="http://2.xiaoyouxi.com/data/4299games/smashing.swf"> </EMBE\
D>
\
</OBJECT>',
'</html>']
soup = BeautifulSoup(''.join(doc))
for a in soup.findAll('a'):
if a.string == a.contents[0] :
s = unicode( a.string )
print pickle.dumps( s )

Reply all
Reply to author
Forward
0 new messages