在 python 中用 lxml 解析 http[s] weboages
parse http[s] weboages with lxml in python
直到最近我才能够解析 table 来自网站 here 的数据。我注意到传输协议从 http
更改为 https
,我认为这就是原因,旧代码不再有效。我收到此错误:IOError: Error reading file '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`
直到最近我才能够解析 table 来自网站 here 的数据。我注意到传输协议从 http
更改为 https
,我认为这就是原因,旧代码不再有效。我收到此错误:IOError: Error reading file '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`