The link I used is here
My procedure of getting the "price" xpath are:
- go to the link using chrome
- use tool
inspect element
- search for the price number
- then come into
<span >some_numbers</span>
- right click the element, then select Copy Full XPATH
- Then I'll get
/html/body/div[2]/div/div[1]/div[3]/div/div[2]/div[1]/div[2]/div[3]/div/div[2]/span[1]
Problem:
Two days ago before this thread, I was using the full xpath I got from chrome inspection, it working just fine in xidel
without a problem. But now,
xidel -se '/html/body/div[2]/div/div[1]/div[3]/div/div[2]/div[1]/div[2]/div[3]/div/div[2]/span[1]' ~/Desktop/document.html
or
xidel -se '/html/body/div[2]/div/div[1]/div[3]/div/div[2]/div[1]/div[2]/div[3]/div/div[2]/span[1]' https://www.cnbc.com/quotes/XAU=
gives me no output...
but, user2703456 given me the "correct" full xpath as follow /html/body/div[2]/div/div[1]/div[3]/div/div/div[1]/div[2]/div[3]/div/div[2]/span[1]
it solved the problem, however, I still confused. when I check both full xpath pointing at the same element, exact same element. why? why it was working before, but now wont?
CodePudding user response:
I suppose it's content comes dynamicly, and somehow the server or javascript changes html.
To overcome this problems i would use not the copied XPath but rely more on a combination of @class en @id attributes i.e. like this:
//*[@id='quote-page-strip']//*[@class='QuoteStrip-lastPrice']