解析特定的网站会导致Python进程崩溃 [英] Parsing a specific website crashes the Python process

查看:173
本文介绍了解析特定的网站会导致Python进程崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

寻找解析HTML页面的图片(来自 http://www.z-img.com ),当我将页面加载到BeautifulSoup(bs4)时,Python崩溃。 问题详细信息显示 etree.pyd 是故障模块名称,这意味着它可能是一个解析错误,但到目前为止,我无法完全确定它的原因。

Looking to parse an HTML page for images (from http://www.z-img.com), and when I load the page into BeautifulSoup (bs4), Python crashes. The "problem details" shows that etree.pyd was the "Fault Module Name", which means its probably a parsing error, but so far, I can't quite nail down the cause of it.

以下是最简单的代码,我可以在Python2.7中加以解释:

Here's the simplest code I can boil it down to, on Python2.7:

import requests, bs4

url = r"http://z-img.com/search.php?&ssg=off&size=large&q=test"
r = requests.get(url)
html = r.content
#or 
#import urllib2
#html = urllib2.urlopen(url).read()
soup  = bs4.BeautifulSoup(html)

以及PasteBin上的示例输出( http://pastebin.com/XYT9g4Lb ),在我通过JsBeautifier.com传递后。

along with a sample output on PasteBin (http://pastebin.com/XYT9g4Lb), after I had passed it through JsBeautifier.com.

推荐答案

这是一个错误这是固定在 lxml 版本2.3.5 。升级到版本2.3.5或更高版本。

This is a bug that was fixed in lxml version 2.3.5. Upgrade to version 2.3.5 or later.

这篇关于解析特定的网站会导致Python进程崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆