pythonxpath返回空列表,而不是值或tex

2024-06-08 19:53:34 发布

您现在位置:Python中文网/ 问答频道 /正文

下面是我的程序,它返回一个空列表,它应该返回值'mar17',请让我知道我做错了这里。你知道吗

import requests
from lxml import html

newline="http://www.moneycontrol.com/financials/20microns/balance-sheetVI/2M"
try:
    page = requests.get(newline, timeout=5)
except requests.Timeout:                                         
    pass
except requests.ConnectionError:
    pass
except requests.ReadTimeout:
    pass
tree = html.fromstring(page.content)
yrs = tree.xpath('//*[@id="mc_mainWrapper"]/div[3]/div[2]/div[3]/div[2]/div[2]/div[2]/div[1]/table[2]/tbody/tr[1]/td[2]')                           
print(yrs)

Tags: fromimport程序divtree列表htmlpage