【发布时间】:2021-07-11 03:36:32
【问题描述】:
所以这是我的问题。我正在尝试使用 lxml 来抓取网站并获取一些信息,但是在使用 var.xpath 命令时找不到与信息相关的元素。它正在查找页面,但在使用 xpath 后,它什么也没找到。
import requests
from lxml import html
def main():
result = requests.get('https://rocketleague.tracker.network/rocket-league/profile/xbl/ReedyOrange/overview')
# the root of the tracker website
page = html.fromstring(result.content)
print('its getting the element from here', page)
threesRank = page.xpath('//*[@id="app"]/div[2]/div[2]/div/main/div[2]/div[3]/div[1]/div/div/div[1]/div[2]/table/tbody/tr[*]/td[3]/div/div[2]/div[1]/div')
print('the 3s rank is: ', threesRank)
if __name__ == "__main__":
main()
OUTPUT:
"D:\Python projects\venv\Scripts\python.exe" "D:/Python projects/main.py"
its getting the element from here <Element html at 0x20eb01006d0>
the 3s rank is: []
Process finished with exit code 0
“the 3s rank is:”旁边的输出应该是这样的
[<Element html at 0x20eb01006d0>, <Element html at 0x20eb01006d0>, <Element html at 0x20eb01006d0>]
【问题讨论】:
标签: python html xpath lxml python-requests-html