简体   繁体   中英

How to find specific value of html element (such as h1) with node.js

I'm trying to find the numbers of users on this website , using node.js, but I'm not sure of what process I can do to get it. The value is subclassed under multiple divs with different class names. Right now I will just be console.logging it but I'm going to do more with the data later on.

I was suggested to use the package "puppeteer", but I'm not sure how this would fetch it or what to do with it to fetch it.

Thank you in advance

You can use Puppeteer and obtain the value via a query string. The typical code looks like this:

 const pt= require('puppeteer') async function getText(){ //launch browser in headless mode const browser = await pt.launch() //browser new page const page = await browser.newPage() //launch URL await page.goto('https://feds.lol/') //identify element const f = await page.$("QUERY_STRIG") //obtain text const text = await (await f.getProperty('textContent')).jsonValue() console.log("Text is: " + text) } getText()

However, I see this website is protected by Captcha

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