I want to know if it is possible to go to a site and retrieve the text of an element
i think something like
a = page("www.site.com")
b = a.getElementByClass("name")
console.log(b.text)
this is possible?
CodePudding user response:
Yes. It's called the innerText property. See https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText
CodePudding user response:
That depends,
If you want to get the innerText
of the elements, then
let elements = document.getElementsByClassName("YourClassName");
for(let i=0;i<elements.length; i ){
/*doSOmething*/
console.log(elements[i].innerText);
}
Many elements may have same className
. So, if you want to access some specific Element, then you should either know the index of the element
or you need to use id
for the element.
let element = document.getElementById("YourElementId");
/*doSOmething*/
console.log(element.innerText);