直到最近我才能够从网站here解析表数据。 。我注意到传输协议(protocol)从 http
更改为 https
,我相信这就是原因,旧代码不再起作用。我收到此错误:IOError:读取文件'https:/....时出错
我的代码基本上是
import lxml.html
page = lxml.html.parse(url)
table = [page.xpath("//tr/td/text()")
我如何继续从 https
网页获取数据,最好坚持使用 lxml
?
最佳答案
你可以这样使用它:
import lxml.html as lh
import requests as r
doc = r.get(yourHttpsUrl).content
html = lh.fromstring(doc)
# now use your xpath on this `html`
关于python - 在python中使用lxml解析http[s] weboages,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42680626/