简体   繁体   English

如何用node.js查找html元素(比如h1)的具体值

[英]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.我正在尝试使用 node.js 查找此网站上的用户数量,但我不确定我可以执行什么过程来获取它。 The value is subclassed under multiple divs with different class names.该值在具有不同 class 名称的多个 div 下进行子分类。 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.我被建议使用 package “puppeteer”,但我不确定这将如何获取它或如何使用它来获取它。

Thank you in advance先感谢您

You can use Puppeteer and obtain the value via a query string.您可以使用 Puppeteer 并通过查询字符串获取值。 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但是,我看到这个网站受验证码保护

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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