使用lxml时,https的处理方式是什么?

编程入门 行业动态 更新时间:2024-10-27 23:21:36
本文介绍了使用lxml时,https的处理方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用lxml解析给定URL的html文件.

I am using lxml to parse html files given urls.

例如:

link = 'abc/def' htmltree = lxml.html.parse(link)

我的代码在大多数情况下(在情况下)运行良好.但是,我发现对于每个网址,lxml都只会得到一个 IOError .有人知道原因吗?并且可能如何解决此问题?

My code is working well for most of the cases, the ones with . However, I found for every url, lxml simply gets an IOError. Does anyone know the reason? And possibly, how to correct this problem?

顺便说一句,鉴于我已经有了一个快速完成的程序,我想坚持使用lxml而不是切换到BeautifulSoup.

BTW, I want to stick to lxml than switch to BeautifulSoup given I've already got a quick finished programme.

推荐答案

我不知道发生了什么,但是我遇到了同样的错误.可能不支持HTTPS.不过,您可以使用urllib2轻松解决此问题:

I don't know what's happening, but I get the same errors. HTTPS is probably not supported. You can easily work around this with urllib2, though:

from lxml import html from urllib2 import urlopen html.parse(urlopen('duckduckgo'))

更多推荐

使用lxml时,https的处理方式是什么?

本文发布于:2023-11-16 11:07:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1603722.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方式   lxml   https

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!