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
#4
Basically, they are way too specific.
You get an XPath that selects a single element, mostly identifying it by its location in the DOM (a b inside the 6th td inside of the 3rd tr inside a tbody of a table inside of a td...).

This means that any simple change in the website will break the XPath, so it might not even work on two pages of the same website.

Another problem is that these XPaths are generated after the web page has been fully rendered, so the browser takes into account any javascript code that was executed (which lxml doesn't do), and in cases of invalid HTML, the browser might add/remove/move some elements (which depends on the browser).
The reason this particular XPath worked with selenium is that selenium probably used the same browser you normally use.
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, 04:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  cleaning HTML pages using lxml and XPath wenkos 2 2,483 Aug-25-2021, 10:54 AM
Last Post: wenkos
  need help with xpath pythonprogrammer 1 2,774 Jan-18-2020, 11:28 PM
Last Post: snippsat
  working with lxml and requests gentoobob 23 11,722 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