2

What xpath should i use to extract only the url link from the below element?

<a class="url" rel="noreferrer" onclick="redirect('https://www.fotbollskanalen.se/allsvenskan/kujovic-siktar-pa-startplats-var-naturligt-att-agera-inhoppare---nu-vill-jag-s');">Läs mer på Fotbollskanalen</a>

I have tried using the below xpath, but it only returns "Läs mer på Fotbollskanalen" and not the url itself.

a[1]/child::node()

Also tried different versions attempting to set specify the class but unable to get it right.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
gson
  • 23
  • 2
  • Does this answer your question? [Getting attribute using XPath](https://stackoverflow.com/questions/4531995/getting-attribute-using-xpath) – Sunny Patel Jan 08 '20 at 19:47

1 Answers1

1

Try this:

substring-before(substring-after(//a/@onclick, "'"),"'")

It will,

  • substring-before(substring-after(foo, "'"),"'"): Get in everything enclosed by ' in foo.
  • //a: Of the element a.
  • /@onclick: Inside the attribute onclick.
adelriosantiago
  • 7,762
  • 7
  • 38
  • 71