English 中文(简体)
在NodeJS进行点击
原标题:Make a click event in NodeJS

我试图从服务器一侧点击。

I m使用NodeJS和I m无法使用JQuery功能。

我要点击<代码>.next类别。

This is what I would do :

while (nbrPage > 0)
{
    //my scraping code
    nbrPage--;
    $( .next ).click();
}

Note than the html code to scrape is like this :

<span class="next">
     <a id="nextPage-159c6fa8635" class="page" href="/blablabla"></a>
</span>

是否有任何人知道在NodeJS法典中如何使用JQuery方法,或如何在NodeJS进行点击?

EDIT:I m报废了一个网站,我希望在每一页旁听,并从每一页中删除我的数据。 为此,我需要下页,并点击以下的《html法典》。 换言之,我将使用“JQuery”的功能,例如$(next .click(>,载于我的分母代码(requestcheerio)。

我不想处理点击事件,但我想点击。

感谢您的帮助

问题回答

Cheerio是一种非常有用的工具,使你能够在诺德利用 j。 JS. 可在

Request is designed to be the simplest way possible to make http calls. It supports HTTPS and follows redirects by default.

查阅文件:

For server-side, you need to create a function to find the a href with the id that started with "nextPage-". Then IF found you will need to get the value of the attribute href.

从那以后,你将把这一价值转回你的“请求”文字,我假定你已经并将继续报废,直到“请求”再找不到。

That repetitive sequence of a function calling itself is called "recursion".

现在,在法典中可以看一看什么?

// Load Dependencies
const CHEERIO = require("cheerio");
const REQUEST = require("request");


/**
 * Scraps HTML to find next page URL
 *
 * @function getNextPageUrl
 *
 * @param   {string} HTML
 *
 * @returns {string || boolean} Returns URL or False
 */
function getNextPageUrl(HTML) {

    // Load in scrapped html
    let $ = CHEERIO.load(HTML);

    // Find ID that starts with `nextPage-`
    let nextPage = $("span[id^= nextPage- ]:first");

    // If it is 0, its false
    if(nextPage.length) {
        // Return href attribute value
        return nextPage.attr("href");
    } else {
        // Nothing found, return false
        return false;
    }

}


/**
 * Scraps the HTML from pages
 *
 * @function scrapper
 *
 * @param   {string} URL
 *
 * @returns {string || boolean} Returns URL or False
 */
function scrapper(URL) {

    // Check if URL was provided
    if(!URL) {
        return fasle;
    } 

    // Send out request to URL
    REQUEST(URL, function(error, response, body) {

        // Check for errors
        if(!error && response.statusCode == 200) {
           console.log(body) // Show the HTML

           // Recursion
           let URL = getNextPageURL(body);
           scrapper(URL);

        } else {
          return false;
        }

    });
}


// Pass to scrapper function test
//console.log(getNextPageURL("<span class= next ><a id= nextPage-159c6fa8635  class= page  href= /blablabla ></a></span>"));

// Start the initial scrapping
scrapper("http://google.com");

It s impossible to do it in Node.js. Node.js is server side, not client side. As a solution, you can parse href at the link and make a request to scrap the next page. This is how the server-side scrappers usually work.





相关问题
Logic for Implementing a Dynamic Web Scraper in C#

I am looking to develop a Web scraper in C# window forms. What I am trying to accomplish is as follows: Get the URL from the user. Load the Web page in the IE UI control(embedded browser) in ...

Capture ASP output for monitoring

How do I Capture ASP.NET output and then store it as temp memory so that I can use them in an application to do comparison. example. there s this site which has ASP output. Sorry I do not have ...

Error in using Python/mechanize select_form()?

I am trying to scrap some data from a website. The scripts I am trying to write, should get the content of the page: http://www.atpworldtour.com/Rankings/Singles.aspx Should simulate the user going ...

Retrieving dynamic text from a website in vb.net (VS2008)

I want to be able to retrieve dynamic data from a web page (share prices). I started out by retrieving the html code before I realised that as it is live data, the html code will be of little use. ...

Programming languages comparison for web data mining task

I need some help comparing different programming languages, such as: C++, Java, Python, Ruby and PHP, for a task which is related for web data mining (developing web crawler, string manipulations and ...

热门标签