我为什么会用BeautifulSoup和IDLE一个递归错误? [英] Why do I get a recursion error with BeautifulSoup and IDLE?
本文介绍了我为什么会用BeautifulSoup和IDLE一个递归错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我下面的教程来尝试学习如何使用BeautifulSoup。我想一个HTML页面我下载上删除的URL的名称。我有这一点伟大的工作。
从BS4进口BeautifulSoup汤= BeautifulSoup(开放(43-congress.html))final_link = soup.p.a
final_link.decompose()链接= soup.find_all('A')在链接的链接:
打印链接
但是当我进入这个下一部分
从BS4进口BeautifulSoup汤= BeautifulSoup(开放(43-congress.html))final_link = soup.p.a
final_link.decompose()链接= soup.find_all('A')在链接的链接:
名称= link.contents [0]
丰联= link.get('href属性)
打印名称
打印丰联
我得到这个错误
回溯(最后最近一次调用):
文件C:/ Python27 / Python的教程/ soupexample.py,13号线,上述<&模块GT;
打印名称
文件C:\\ Python27 \\ lib目录\\ idlelib \\ PyShell.py,线路1325,在写
返回self.shell.write(S,self.tags)
文件C:\\ Python27 \\ lib目录\\ idlelib \\ rpc.py,595线,在__call__
值= self.sockio.remotecall(self.oid,self.name,ARGS,kwargs)
文件C:\\ Python27 \\ lib目录\\ idlelib \\ rpc.py,210线,在为RemoteCall
SEQ = self.asynccall(OID,方法名,ARGS,kwargs)
文件C:\\ Python27 \\ lib目录\\ idlelib \\ rpc.py,225线,在asynccall
self.putmessage((SEQ,要求))
文件C:\\ Python27 \\ lib目录\\ idlelib \\ rpc.py,324线,在PUTMESSAGE
S = pickle.dumps(消息)
文件C:\\ Python27 \\ lib目录\\ copy_reg.py,第74行,在_reduce_ex
=有getstate自我.__ getstate__
RuntimeError:最大递归深度超过
解决方案
这是空闲和BeautifulSoup的 NavigableString
对象(子类之间的越野车互动UNI code
)。请参见问题1757057 ;它已经有一段时间了。
的解决办法是将对象转换为纯UNI code值第一:
打印UNI code(地名)
I am following a tutorial to try to learn how to use BeautifulSoup. I am trying to remove names from the urls on a html page I downloaded. I have it working great to this point.
from bs4 import BeautifulSoup
soup = BeautifulSoup(open("43rd-congress.html"))
final_link = soup.p.a
final_link.decompose()
links = soup.find_all('a')
for link in links:
print link
but when I enter this next part
from bs4 import BeautifulSoup
soup = BeautifulSoup(open("43rd-congress.html"))
final_link = soup.p.a
final_link.decompose()
links = soup.find_all('a')
for link in links:
names = link.contents[0]
fullLink = link.get('href')
print names
print fullLink
I get this error
Traceback (most recent call last):
File "C:/Python27/python tutorials/soupexample.py", line 13, in <module>
print names
File "C:\Python27\lib\idlelib\PyShell.py", line 1325, in write
return self.shell.write(s, self.tags)
File "C:\Python27\lib\idlelib\rpc.py", line 595, in __call__
value = self.sockio.remotecall(self.oid, self.name, args, kwargs)
File "C:\Python27\lib\idlelib\rpc.py", line 210, in remotecall
seq = self.asynccall(oid, methodname, args, kwargs)
File "C:\Python27\lib\idlelib\rpc.py", line 225, in asynccall
self.putmessage((seq, request))
File "C:\Python27\lib\idlelib\rpc.py", line 324, in putmessage
s = pickle.dumps(message)
File "C:\Python27\lib\copy_reg.py", line 74, in _reduce_ex
getstate = self.__getstate__
RuntimeError: maximum recursion depth exceeded
解决方案
This is a buggy interaction between IDLE and BeautifulSoup's NavigableString
objects (which subclass unicode
). See issue 1757057; it's been around for a while.
The work-around is to convert the object to a plain unicode value first:
print unicode(names)
这篇关于我为什么会用BeautifulSoup和IDLE一个递归错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文