1

I wish to extract a link on a set of pages. Sometimes this link is defined on a page as:

//*[@id="mainlist"]/dl/dt[3]/a

and sometimes as:

//*[@id="mainlist"]/dl[2]/dt[2]/a

The text associated with the link is always "My special link".

Is there a way to match a href child of //*[@id="mainlist"] which has the text "My special link"?

Baz
  • 11,687
  • 35
  • 137
  • 244

1 Answers1

1

Yes, you can do:

"//*[@id="mainlist"]//a[text()="My special link"]"

With cssselect you can do

"#mainlist a:contains("My special link")"
pguardiario
  • 51,516
  • 17
  • 106
  • 147