2

I am trying to get all href links via xpath from the following page:

href page

I tried the following:

//div[@class='article-tile__images']/a[@class='article-tile__link js-article-tile__link acte-article-catalogName-lnk']

Any suggestions what I am doing wrong?

I appreciate your replies!

Carol.Kar
  • 4,581
  • 36
  • 131
  • 264
  • `xmllint --html` throws an enormous number of errors about the page: XPath is going to be dodgy as a result. – bishop Aug 09 '16 at 18:00
  • @bishop, unfortunately, I think that xmllint is not yet aware of HTML5 tags and rejects them. There is probably a way to feed the correct "DTD" although HTML5 does not offer such per se... (since it's really extensible.) – Alexis Wilke May 07 '18 at 00:34

1 Answers1

3

Working with class attributes is much easier, readable and concise in CSS selectors:

a.article-tile__link

which matches 65 links when I issue $$('a.article-tile__link') in the Chrome console.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Thx for your quick answer! How would the above look in xpath? – Carol.Kar Aug 09 '16 at 17:59
  • 1
    @mrquad well, the simplest one would be `//a[contains(@class, "article-tile__link")]`. But, if you are going to stick to xpath here, better use `concat()` to handle multiple classes more reliably and avoid surprises, see http://stackoverflow.com/a/5662452/771848. Thanks. – alecxe Aug 09 '16 at 18:04