1

is there a way in puppeteer to get the href attribute of an anchor element with text "See more".

I want to grab the href attribute of an element like this:

<a href="/this-is-what-i-want">See more</a>

maybe it's possble to do with eval?

gabogabans
  • 3,035
  • 5
  • 33
  • 81

2 Answers2

0

you could try looping through all links

document.querySelectorAll('a').forEach(link => link.innerText === "See more"  )

This might not work with newer JavaScript versions since querySelectorAll as well as getElementsByTagName do not yield an Array but HTMLCollection which is not iterable using forEach. See the linked answers on SO on how to fix this.

pas-calc
  • 115
  • 9
-1

maybe you should try native js

url=document.getElementById("Id_of_AnchorTag").href;

keep in mind that you must be able to uniquely identify the anchor by some method.

nikhil swami
  • 2,360
  • 5
  • 15