beautifulsoup 4:分段故障(核心转储)

Tao*_*sof 3 python screen-scraping beautifulsoup web-scraping

我抓了以下页面:

http://www.nasa.gov/topics/earth/features/plains-tornadoes-20120417.html

但是在调用时遇到了Segmentation fault(core dumped):BeautifulSoup(page_html),其中page_html是来自请求库的内容.这是BeautifulSoup的错误吗?有没有办法解决这个问题?甚至像try一样的方法...除了帮助我运行我的代码.提前致谢.

代码如下:

import requests
from bs4 import BeautifulSoup

toy_url = 'http://www.nasa.gov/topics/earth/features/plains-tornadoes-20120417.html'
res = requests.get(toy_url,headers={"USER-Agent":"Firefox/12.0"})
page = res.content
soup = BeautifulSoup(page)
Run Code Online (Sandbox Code Playgroud)

Leo*_*son 5

此问题是由lxml中的错误引起的,该错误在lxml 2.3.5中得到修复.您可以升级lxml,或使用带有html5lib或HTMLParser解析器的Beautiful Soup.