【发布时间】:2021-04-18 08:49:50
【问题描述】:
我正在尝试使用 python 进行网络抓取。我是新手。我想从表中提取数据。我正在使用 xPath helper 的帮助,但是当它转向代码时它似乎无法工作。
下面是我的代码
import requests
from lxml import html
url = 'https://www.hybrid-analysis.com/sample/a1b38a18decb253708e0198bfaaed97ef1c16fc061f1dc8c1ba00e98ef77092e/5ff1a85664a2e10f370a6c02'
headers = {'User-Agent':'Mozilla/5.0'}
req = requests.get(url, headers = headers)
print(req.status_code)
tree = html.fromstring(req.content)
NetA = tree.xpath('//section[@id="sample-network-traffic"]/h2/text()')
dns1 = tree.xpath('//section[@id="sample-network-traffic"]/div[@id="dns-requests"]/h3/text()')
dnst = tree.xpath('//div[@id="dns-requests"]//table[@class="table table-striped small"]/thead/tr/th[contains(@class,'col-md')]/text()')
print(NetA)
print(dns1)
print(dnst)
当我在代码中时,我无法从表的线程中提取数据。但是我的 xPath 在 XPath Helper 中很好
【问题讨论】:
标签: python-3.x xpath jupyter-notebook pycharm