我正在使用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的处理方式是什么?
发布评论