Python Forum
[Help]xpath is not working with lxml
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Help]xpath is not working with lxml
#2
Just copying an xpath from your browser's developer tools is rarely gonna work, at least reliably.
I would recommend learning the basics of xpath, and writing xpath expressions yourself.

Here are a couple of ways you can get what you want (this is a scrapy shell session, but the same xpaths will work in lxml):
>>> # the 6th cell of the 3rd row of the "snapshot-table2"
>>> response.xpath('//table[@class="snapshot-table2"]//tr[3]/td[6]/b/text()').get()
'0.95'
>>> # the cell after the one containing the text "EPS next Q"
>>> response.xpath('//td[.="EPS next Q"]/following-sibling::td[1]/b/text()').get()
Reply


Messages In This Thread
[Help]xpath is not working with lxml - by mr_byte31 - Jul-22-2018, 10:14 AM
RE: [Help]xpath is not working with lxml - by stranac - Jul-22-2018, 11:21 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  cleaning HTML pages using lxml and XPath wenkos 2 2,528 Aug-25-2021, 10:54 AM
Last Post: wenkos
  need help with xpath pythonprogrammer 1 2,805 Jan-18-2020, 11:28 PM
Last Post: snippsat
  working with lxml and requests gentoobob 23 11,832 Apr-19-2018, 06:54 PM
Last Post: gentoobob

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020