使用lxml时,https的处理方式是什么? [英] What is the deal about https when using lxml?
问题描述
我正在使用lxml解析给定URL的html文件.
I am using lxml to parse html files given urls.
例如:
link = 'https://abc.com/def'
htmltree = lxml.html.parse(link)
我的代码在大多数情况下(在http://
情况下)运行良好.但是,我发现对于每个https://
网址,lxml都只会得到一个 IOError .有人知道原因吗?并且可能如何解决此问题?
My code is working well for most of the cases, the ones with http://
. However, I found for every https://
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('https://duckduckgo.com'))
这篇关于使用lxml时,https的处理方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!