简体   繁体   中英

How to get text from a web page - document.getElementsByClassName

I'm trying to get some text from the website.

I tried this, but it doesn't work, it gives me "undefined"

CurBrowser.GetMainFrame().ExecuteJavaScriptAsync("var elems1 = document.getElementsByClassName('some-text')");
            CurBrowser.GetMainFrame().ExecuteJavaScriptAsync("for(var i = 0; i < elems1.length; i++){var textt = elems1[i].innerText}");
            CurBrowser.GetMainFrame().ExecuteJavaScriptAsync("alert(textt)");

and this is what I am trying to target

<p class="some-text">
        hello World
    </p>

 const elements = document.getElementsByClassName('some-text'); for (const element of elements) { console.log(element.innerText); }
 <p class="some-text"> Text from paragraph 1 </p> <p class="some-text"> Text from paragraph 2 </p>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM