pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <tfoot id='iWDZT'></tfoot>

        <legend id='iWDZT'><style id='iWDZT'><dir id='iWDZT'><q id='iWDZT'></q></dir></style></legend>

        <small id='iWDZT'></small><noframes id='iWDZT'>

      1. <i id='iWDZT'><tr id='iWDZT'><dt id='iWDZT'><q id='iWDZT'><span id='iWDZT'><b id='iWDZT'><form id='iWDZT'><ins id='iWDZT'></ins><ul id='iWDZT'></ul><sub id='iWDZT'></sub></form><legend id='iWDZT'></legend><bdo id='iWDZT'><pre id='iWDZT'><center id='iWDZT'></center></pre></bdo></b><th id='iWDZT'></th></span></q></dt></tr></i><div class="3i0xzu0" id='iWDZT'><tfoot id='iWDZT'></tfoot><dl id='iWDZT'><fieldset id='iWDZT'></fieldset></dl></div>
        • <bdo id='iWDZT'></bdo><ul id='iWDZT'></ul>

        超出最大遞歸深度.多處理和 bs4

        Maximum recursion depth exceeded. Multiprocessing and bs4(超出最大遞歸深度.多處理和 bs4)

      2. <small id='URL8G'></small><noframes id='URL8G'>

          <i id='URL8G'><tr id='URL8G'><dt id='URL8G'><q id='URL8G'><span id='URL8G'><b id='URL8G'><form id='URL8G'><ins id='URL8G'></ins><ul id='URL8G'></ul><sub id='URL8G'></sub></form><legend id='URL8G'></legend><bdo id='URL8G'><pre id='URL8G'><center id='URL8G'></center></pre></bdo></b><th id='URL8G'></th></span></q></dt></tr></i><div class="5ppvbdb" id='URL8G'><tfoot id='URL8G'></tfoot><dl id='URL8G'><fieldset id='URL8G'></fieldset></dl></div>

              • <bdo id='URL8G'></bdo><ul id='URL8G'></ul>

                <tfoot id='URL8G'></tfoot>

                  <legend id='URL8G'><style id='URL8G'><dir id='URL8G'><q id='URL8G'></q></dir></style></legend>

                    <tbody id='URL8G'></tbody>
                  本文介紹了超出最大遞歸深度.多處理和 bs4的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  限時(shí)送ChatGPT賬號(hào)..

                  我正在嘗試讓解析器使用 beautifulSoup 和多處理.我有一個(gè)錯(cuò)誤:

                  I'm trying to make a parser use beautifulSoup and multiprocessing. I have an error:

                  RecursionError: 超出最大遞歸深度

                  RecursionError: maximum recursion depth exceeded

                  我的代碼是:

                  import bs4, requests, time
                  from multiprocessing.pool import Pool
                  
                  html = requests.get('https://www.avito.ru/moskva/avtomobili/bmw/x6?sgtd=5&radius=0')
                  soup = bs4.BeautifulSoup(html.text, "html.parser")
                  
                  divList = soup.find_all("div", {'class': 'item_table-header'})
                  
                  
                  def new_check():
                      with Pool() as pool:
                          pool.map(get_info, divList)
                  
                  def get_info(each):
                     pass
                  
                  if __name__ == '__main__':
                      new_check()
                  

                  為什么會(huì)出現(xiàn)此錯(cuò)誤以及如何解決?

                  Why I get this error and how I can fix it?

                  更新:所有錯(cuò)誤文本都是

                  Traceback (most recent call last):
                    File "C:/Users/eugen/PycharmProjects/avito/main.py", line 73, in <module> new_check()
                    File "C:/Users/eugen/PycharmProjects/avito/main.py", line 67, in new_check
                      pool.map(get_info, divList)
                    File "C:UserseugenAppDataLocalProgramsPythonPython36libmultiprocessingpool.py", line 266, in map
                      return self._map_async(func, iterable, mapstar, chunksize).get()
                    File "C:UserseugenAppDataLocalProgramsPythonPython36libmultiprocessingpool.py", line 644, in get
                      raise self._value
                    File "C:UserseugenAppDataLocalProgramsPythonPython36libmultiprocessingpool.py", line 424, in _handle_tasks
                      put(task)
                    File "C:UserseugenAppDataLocalProgramsPythonPython36libmultiprocessingconnection.py", line 206, in send
                      self._send_bytes(_ForkingPickler.dumps(obj))
                    File "C:UserseugenAppDataLocalProgramsPythonPython36libmultiprocessing
                  eduction.py", line 51, in dumps
                      cls(buf, protocol).dump(obj)
                  RecursionError: maximum recursion depth exceeded
                  

                  推薦答案

                  當(dāng)你使用 multiprocessing 時(shí),你傳遞給 worker 的所有東西都必須是 腌制.

                  When you use multiprocessing, everything you pass to a worker has to be pickled.

                  很遺憾,很多 BeautifulSoup 樹無法腌制.

                  Unfortunately, many BeautifulSoup trees can't be pickled.

                  這有幾個(gè)不同的原因.其中一些是已修復(fù)的錯(cuò)誤,因此您可以嘗試確保您擁有最新的 bs4 版本,而有些則特定于不同的解析器或樹構(gòu)建器......但很有可能沒有這樣的事情會(huì)有幫助的.

                  There are a few different reasons for this. Some of them are bugs that have since been fixed, so you could try making sure you have the latest bs4 version, and some are specific to different parsers or tree builders… but there's a good chance nothing like this will help.

                  但根本問題是樹中的許多元素都包含對(duì)樹其余部分的引用.

                  But the fundamental problem is that many elements in the tree contain references to the rest of the tree.

                  有時(shí),這會(huì)導(dǎo)致實(shí)際的無限循環(huán),因?yàn)檠h(huán)引用對(duì)于其循環(huán)引用檢測來說過于間接.但這通常是一個(gè)可以修復(fù)的錯(cuò)誤.

                  Occasionally, this leads to an actual infinite loop, because the circular references are too indirect for its circular reference detection. But that's usually a bug that gets fixed.

                  但是,更重要的是,即使循環(huán)不是無限,它仍然可以從樹的其余部分拖入 1000 多個(gè)元素,這已經(jīng)足以導(dǎo)致遞歸錯(cuò)誤.

                  But, even more importantly, even when the loop isn't infinite, it can still drag in more than 1000 elements from all over the rest of the tree, and that's already enough to cause a RecursionError.

                  我認(rèn)為后者就是這里發(fā)生的事情.如果我使用您的代碼并嘗試腌制 divList[0],它會(huì)失敗.(如果我提高遞歸限制并計(jì)算幀數(shù),它需要 23080 的深度,這遠(yuǎn)遠(yuǎn)超過默認(rèn)的 1000.)但是如果我采用完全相同的 div 并解析分開,它成功沒有問題.

                  And I think the latter is what's happening here. If I take your code and try to pickle divList[0], it fails. (If I bump the recursion limit way up and count the frames, it needs a depth of 23080, which is way, way past the default of 1000.) But if I take that exact same div and parse it separately, it succeeds with no problem.

                  所以,一種可能性是只做 sys.setrecursionlimit(25000).這將解決這個(gè)確切頁面的問題,但是稍微不同的頁面可能需要更多.(另外,將遞歸限制設(shè)置得那么高通常不是一個(gè)好主意——不是因?yàn)槔速M(fèi)了內(nèi)存,而是因?yàn)檫@意味著實(shí)際的無限遞歸需要 25 倍的時(shí)間和 25 倍的資源浪費(fèi)來檢測.)

                  So, one possibility is to just do sys.setrecursionlimit(25000). That will solve the problem for this exact page, but a slightly different page might need even more than that. (Plus, it's usually not a great idea to set the recursion limit that high—not so much because of the wasted memory, but because it means actual infinite recursion takes 25x as long, and 25x as much wasted resources, to detect.)

                  另一個(gè)技巧是編寫修剪樹"的代碼,在您腌制之前/之后消除 div 中的任何向上鏈接.這是一個(gè)很好的解決方案,但它可能需要大量工作,并且需要深入了解 BeautifulSoup 的工作原理,我懷疑你是否愿意這樣做.

                  Another trick is to write code that "prunes the tree", eliminating any upward links from the div before/as you pickle it. This is a great solution, except that it might be a lot of work, and requires diving into the internals of how BeautifulSoup works, which I doubt you want to do.

                  最簡單的解決方法有點(diǎn)笨拙,但是……您可以將湯轉(zhuǎn)換為字符串,將其傳遞給孩子,然后讓孩子重新解析它:

                  The easiest workaround is a bit clunky, but… you can convert the soup to a string, pass that to the child, and have the child re-parse it:

                  def new_check():
                      divTexts = [str(div) for div in divList]
                      with Pool() as pool:
                          pool.map(get_info, divTexts)
                  
                  def get_info(each):
                      div = BeautifulSoup(each, 'html.parser')
                  
                  if __name__ == '__main__':
                      new_check()
                  

                  這樣做的性能成本可能無關(guān)緊要;更大的擔(dān)憂是,如果您的 HTML 不完美,則轉(zhuǎn)換為字符串并重新解析它可能不是完美的往返.所以,我建議你先做一些沒有多處理的測試,以確保這不會(huì)影響結(jié)果.

                  The performance cost for doing this is probably not going to matter; the bigger worry is that if you had imperfect HTML, converting to a string and re-parsing it might not be a perfect round trip. So, I'd suggest that you do some tests without multiprocessing first to make sure this doesn't affect the results.

                  這篇關(guān)于超出最大遞歸深度.多處理和 bs4的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  What exactly is Python multiprocessing Module#39;s .join() Method Doing?(Python 多處理模塊的 .join() 方法到底在做什么?)
                  Passing multiple parameters to pool.map() function in Python(在 Python 中將多個(gè)參數(shù)傳遞給 pool.map() 函數(shù))
                  multiprocessing.pool.MaybeEncodingError: #39;TypeError(quot;cannot serialize #39;_io.BufferedReader#39; objectquot;,)#39;(multiprocessing.pool.MaybeEncodingError: TypeError(cannot serialize _io.BufferedReader object,)) - IT屋-程序員軟件開
                  Python Multiprocess Pool. How to exit the script when one of the worker process determines no more work needs to be done?(Python 多進(jìn)程池.當(dāng)其中一個(gè)工作進(jìn)程確定不再需要完成工作時(shí),如何退出腳本?) - IT屋-程序員
                  How do you pass a Queue reference to a function managed by pool.map_async()?(如何將隊(duì)列引用傳遞給 pool.map_async() 管理的函數(shù)?)
                  yet another confusion with multiprocessing error, #39;module#39; object has no attribute #39;f#39;(與多處理錯(cuò)誤的另一個(gè)混淆,“模塊對(duì)象沒有屬性“f)

                  • <i id='oDapw'><tr id='oDapw'><dt id='oDapw'><q id='oDapw'><span id='oDapw'><b id='oDapw'><form id='oDapw'><ins id='oDapw'></ins><ul id='oDapw'></ul><sub id='oDapw'></sub></form><legend id='oDapw'></legend><bdo id='oDapw'><pre id='oDapw'><center id='oDapw'></center></pre></bdo></b><th id='oDapw'></th></span></q></dt></tr></i><div class="li03ytz" id='oDapw'><tfoot id='oDapw'></tfoot><dl id='oDapw'><fieldset id='oDapw'></fieldset></dl></div>
                    <tfoot id='oDapw'></tfoot>
                        • <bdo id='oDapw'></bdo><ul id='oDapw'></ul>
                            <tbody id='oDapw'></tbody>

                          <small id='oDapw'></small><noframes id='oDapw'>

                          <legend id='oDapw'><style id='oDapw'><dir id='oDapw'><q id='oDapw'></q></dir></style></legend>
                            主站蜘蛛池模板: 圆窗水平仪|伊莉莎冈特elesa+ganter| 硅PU球场、篮球场地面施工「水性、环保、弹性」硅PU材料生产厂家-广东中星体育公司 | 国际线缆连接网 - 连接器_线缆线束加工行业门户网站 | 时代北利离心机,实验室离心机,医用离心机,低速离心机DT5-2,美国SKC采样泵-上海京工实业有限公司 工业电炉,台车式电炉_厂家-淄博申华工业电炉有限公司 | 流量检测仪-气密性检测装置-密封性试验仪-东莞市奥图自动化科技有限公司 | 深圳快餐店设计-餐饮设计公司-餐饮空间品牌全案设计-深圳市勤蜂装饰工程 | 天津仓储物流-天津电商云仓-天津云仓一件代发-博程云仓官网 | 临海涌泉蜜桔官网|涌泉蜜桔微商批发代理|涌泉蜜桔供应链|涌泉蜜桔一件代发 | 植筋胶-粘钢胶-碳纤维布-碳纤维板-环氧砂浆-加固材料生产厂家-上海巧力建筑科技有限公司 | 暖气片十大品牌厂家_铜铝复合暖气片厂家_暖气片什么牌子好_欣鑫达散热器 | 智能门锁电机_智能门锁离合器_智能门锁电机厂家-温州劲力智能科技有限公司 | 衬氟旋塞阀-卡套旋塞阀-中升阀门首页| 天空彩票天下彩,天空彩天空彩票免费资料,天空彩票与你同行开奖,天下彩正版资料大全 | 道达尔润滑油-食品级润滑油-道达尔导热油-合成导热油,深圳道达尔代理商合-深圳浩方正大官网 | 低浓度恒温恒湿称量系统,强光光照培养箱-上海三腾仪器有限公司 | 全国国际学校排名_国际学校招生入学及学费-学校大全网 | 空冷器|空气冷却器|空水冷却器-无锡赛迪森机械有限公司[官网] | 无锡市珂妮日用化妆品有限公司|珂妮日化官网|洗手液厂家 | 净化工程_无尘车间_无尘车间装修-广州科凌净化工程有限公司 | 塑料瓶罐_食品塑料瓶_保健品塑料瓶_调味品塑料瓶–东莞市富慷塑料制品有限公司 | 单级/双级旋片式真空泵厂家,2xz旋片真空泵-浙江台州求精真空泵有限公司 | 球磨机,节能球磨机价格,水泥球磨机厂家,粉煤灰球磨机-吉宏机械制造有限公司 | 河南15年专业网站建设制作设计,做网站就找郑州启凡网络公司 | 活性氧化铝球|氧化铝干燥剂|分子筛干燥剂|氢氧化铝粉-淄博同心材料有限公司 | 跨境物流_美国卡派_中大件运输_尾程派送_海外仓一件代发 - 广州环至美供应链平台 | 创富网-B2B网站|供求信息网|b2b平台|专业电子商务网站 | 单电机制砂机,BHS制砂机,制沙机设备,制砂机价格-正升制砂机厂家 单级/双级旋片式真空泵厂家,2xz旋片真空泵-浙江台州求精真空泵有限公司 | 砂石生产线_石料生产线设备_制砂生产线设备价格_生产厂家-河南中誉鼎力智能装备有限公司 | 气体检测仪-氢气检测仪-可燃气体传感器-恶臭电子鼻-深国安电子 | 水冷式工业冷水机组_风冷式工业冷水机_水冷螺杆冷冻机组-深圳市普威机械设备有限公司 | 安规_综合测试仪,电器安全性能综合测试仪,低压母线槽安规综合测试仪-青岛合众电子有限公司 | 企典软件一站式企业管理平台,可私有、本地化部署!在线CRM客户关系管理系统|移动办公OA管理系统|HR人事管理系统|人力 | 原子吸收设备-国产分光光度计-光谱分光光度计-上海光谱仪器有限公司 | 工业胀紧套_万向节联轴器_链条-规格齐全-型号选购-非标订做-厂家批发价格-上海乙谛精密机械有限公司 | 冷轧机|两肋冷轧机|扁钢冷轧机|倒立式拉丝机|钢筋拔丝机|收线机-巩义市华瑞重工机械制造有限公司 | 123悬赏网_发布悬赏任务_广告任务平台 | 微妙网,专业的动画师、特效师、CG模型设计师网站! - wmiao.com 超声波电磁流量计-液位计-孔板流量计-料位计-江苏信仪自动化仪表有限公司 | 阜阳成人高考_阜阳成考报名时间_安徽省成人高考网 | 成都顶呱呱信息技术有限公司-贷款_个人贷款_银行贷款在线申请 - 成都贷款公司 | 全国国际学校排名_国际学校招生入学及学费-学校大全网 | 卷筒电缆-拖链电缆-特种柔性扁平电缆定制厂家「上海缆胜」 |