match div's id suffix


#1

Hello,
In a site I am interested in, the id of the div that contains the full article changes from time to time.
Right now this works:

body: //div[@id='_ctl10__ctl0_Article']

But soon the id will change to something like _ctl12__ctl0_Article.
The last part _Article never changes.
How could I make a rule that always matches this div?
Thanks in advance,
George


#2

Hi George, you can use XPath 1.0 string functions to achieve this. In this case, something like:

body: //div[contains(@id, '_Article')]

This should match any div element which has an id attribute containing ‘_Article’.

XPath 2.0 has an ‘ends-with’ function, but PHP uses XPath 1.0. If the string must appear at the end, you can try the solution suggested here: http://stackoverflow.com/questions/5435310/php-xpath-ends-with