gpt4 book ai didi

python - beautifulsoup 4 : Segmentation fault (core dumped)

转载 作者:太空宇宙 更新时间:2023-11-03 13:49:03 25 4
gpt4 key购买 nike

我抓取了以下页面:

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

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

代码如下:

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)

最佳答案

这个问题是由a bug in lxml引起的,已在 lxml 2.3.5 中修复。您可以升级 lxml,或将 Beautiful Soup 与 html5lib 或 HTMLParser 解析器一起使用。

关于python - beautifulsoup 4 : Segmentation fault (core dumped),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13323469/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com