【发布时间】:2018-02-19 22:47:08
【问题描述】:
https://next.newsimpact.com/NewsWidget/Live
我正在尝试编写一个 python 脚本,该脚本将从上面链接中的 HTML 表中获取一个值。上面的链接是我试图从中获取的站点,这是我编写的代码。我认为我的 XPath 可能不正确,因为它在其他元素上运行良好,但我使用的路径没有返回/打印任何内容。
from lxml import html
import requests
page = requests.get('https://next.newsimpact.com/NewsWidget/Live')
tree = html.fromstring(page.content)
#This will create a list of buyers:
value = tree.xpath('//*[@id="table9521"]/tr[1]/td[4]/text()')
print('Value: ', value)
奇怪的是,当我打开查看源代码页面时,我找不到要从中提取的表。 感谢您的帮助!
【问题讨论】:
-
预期输出是什么?
-
2,632 @GillesQuenot
-
把你的“导入”行也放进去
-
糟糕,我现在将它们包含在代码中。 @GillesQuenot
标签: python html xpath python-requests