最大递归深度达到

最大递归深度达到

本文介绍了Beautifulsoup,最大递归深度达到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是抓住所有的&LT中含量 beautifulsoup 程序; P> HTML标签。抓住一些网页上的内容后,我得到的,说最大递归深度超过了一个错误。

 高清printText(标签):
    在标签标签:
        如果标签.__ class__ == NavigableString:
            打印标签,
        其他:
            printText(标签)
    打印
#LOOP过的网址,送汤printText程序

跟踪底:

 文件web_content.py,第16行,在printText
    printText(标签)
  文件web_content.py,第16行,在printText
    printText(标签)
  文件web_content.py,第16行,在printText
    printText(标签)
  文件web_content.py,第16行,在printText
    printText(标签)
  文件web_content.py,第16行,在printText
    printText(标签)
  文件web_content.py,13号线,在printText
    如果标签.__ class__ == NavigableString:
RuntimeError:最大递归深度超过CMP


解决方案

您可能是达到了一个字符串。遍历字符串收益率1长度的字符串。迭代,1 - 长度的字符串产生一个1长度的字符串。迭代的的1长度的字符串...

This is a beautifulsoup procedure that grabs content within all <p> html tags. After grabbing content from some web pages, I get an error that says maximum recursion depth exceeded.

def printText(tags):
    for tag in tags:
        if tag.__class__ == NavigableString:
            print tag,
        else:
            printText(tag)
    print ""
#loop over urls, send soup to printText procedure

The bottom of trace:

 File "web_content.py", line 16, in printText
    printText(tag)
  File "web_content.py", line 16, in printText
    printText(tag)
  File "web_content.py", line 16, in printText
    printText(tag)
  File "web_content.py", line 16, in printText
    printText(tag)
  File "web_content.py", line 16, in printText
    printText(tag)
  File "web_content.py", line 13, in printText
    if tag.__class__ == NavigableString:
RuntimeError: maximum recursion depth exceeded in cmp
解决方案

You probably hit a string. Iterating over a string yields 1-length strings. Iterating over that 1-length string yields a 1-length string. Iterating over THAT 1-length string...

这篇关于Beautifulsoup,最大递归深度达到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 20:25