Reputation: 25
I'm scraping https://en.wikipedia.org/wiki/Gadsden,_Alabama and I want to grab the "Geography and climate" paragraph and all the text()
elements until the next h2
tag occurs (which is "Demographics").
I don't want to grab the table in here.
the XPath code I've tried so far is //span[@id='Geography_and_climate']/following::p
which selects everything until the page ends.
I've tried answers' code of similar problems on StackOverflow but nothing works for me, maybe I'm not an expert to understand their code.
Upvotes: 1
Views: 311
Reputation: 407
Try this XPath to select all paragraphs after Geography&Climate and before Demographics
//p[preceding-sibling::h2[1][span[@id='Geography_and_climate']]]
Upvotes: 1