I want to parse the following webpage:
https://mafiaworldtour.com/tournaments/2653
And I need to find the following element:
//html/body/div[1]/div/section[2]/div/div/div/div[1]/div[1]/div/div[2]/div/div[1]/div[2]/span/text()
When I search it on the webpage via inspect, it is clearly present, but
city = response.xpath('//html/body/div[1]/div/section[2]/div/div/div/div[1]/div[1]/div/div[2]/div/div[1]/div[2]/span/text()').extract_first()
returns None.
What is the reason for this?
I expect to get the city Хайфа, Израиль
of the tournament via xpath.
2
Answers
Using my own project retrieveCssOrXpathSelectorFromTextOrNode to fetch the full xpath query:
It’s always better to have these specific
XPath
query’s than the one with relative path like auto-generated bychrome dev tools
:But you can remove the useless part, should be like:
(From
chrome dev tools
, orfirefox
console):or in your case:
Output
you can use both CSS selector orXPATH
CSS selector
XPATH