I want to extract the value from the given xpath:
'//*[@id="octable"]/tbody/tr[34]/td[8]/b
to Python.
import requests
from lxml import html
pageContent=requests.get('https://nseindia.com/live_market/dynaContent/live_watch/option_chain/optionKeys.jsp?symbolCode=209&symbol=INFY&symbol=INFY&instrument=-&date=-&segmentLink=17&symbolCount=2&segmentLink=17')
tree = html.fromstring(pageContent.content)
g=tree.xpath('//*[@id="octable"]/tbody/tr[34]/td[8]/b/text()')
print(g)
Expected result: 7,962,000
Actual result: []
使用g=tree.xpath('//*[@id="octable"]/tr/td[8]/b/text()')
代替g=tree.xpath('//*[@id="octable"]/tbody/tr[34]/td[8]/b/text()')
产生预期的结果。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.