python - 在python中使用lxml解析http[s] weboages

标签 python html-parsing python-requests lxml

直到最近我才能够从网站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/

相关文章:

reactjs - 无法解析安装 html-parser 的依赖关系

c# - HTML 敏捷包 - 解析表

python - 向 Telegram 发送图像时出现 'Request Entity Too Large' 错误是什么原因?

python - 使用 shell 管道时 subprocess.run 的返回码

python - Python 类中的公共(public)变量?

python - 用 julia 计算主值积分

python - 是否可以在 python 多处理中重新启动已经终止的进程?

PHP解析无效的html

python - 为什么请求没有发送数据?

python - Google App Engine 中的证书存储