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
  • 12,713
  • 38
  • 145
  • 268

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
  • 53,827
  • 19
  • 119
  • 159