GithubHelp home page GithubHelp logo

testscrapper's Introduction

Testing Web scrapper using this: https://blog.bitsrc.io/https-blog-bitsrc-io-how-to-perform-web-scraping-using-node-js-5a96203cb7cb

https://blog.bitsrc.io/how-to-perform-web-scraping-using-node-js-part-2-7a365aeedb43

install dep npm init -y npm install nightmare cheerio --unsafe-perm=true

const Nightmare = require('nightmare'); const cheerio = require('cheerio');

const nightmare = Nightmare({ show: true }) const url = 'https://news.ycombinator.com';

// Request making using nightmare nightmare .goto(url) .wait('body') .evaluate(() => document.querySelector('body').innerHTML) .end() .then(response => { console.log(getData(response)); }).catch(err => { console.log(err); });

// Parsing data using cheerio let getData = html => { data = []; const $ = cheerio.load(html); $('table.itemlist tr td:nth-child(3)').each((i, elem) => { data.push({ title : $(elem).text(), link : $(elem).find('a.storylink').attr('href') }); }); return data; }

const nightmare = Nightmare({ show: true }) const url = 'https://www.flipkart.com/';

// Request making using nightmare nightmare .goto(url) .wait('body') .click('button._2AkmmA._29YdH8') .type('input.LM6RPg', 'nodejs books') .click('button.vh79eN') .wait('div.bhgxx2') .evaluate(() => document.querySelector('body').innerHTML) .end() .then(response => { console.log(getData(response)); }).catch(err => { console.log(err); });

// Parsing data using cheerio let getData = html => { data = []; const $ = cheerio.load(html); $('div._1HmYoV._35HD7C:nth-child(2) div.bhgxx2.col-12-12').each((row, raw_element) => { $(raw_element).find('div div div').each((i, elem) => { let title = $(elem).find('div div a:nth-child(2)').text(); let link = $(elem).find('div div a:nth-child(2)').attr('href'); if (title) { data.push({ title : title, link : link }); } }); }); return data; }

testscrapper's People

Contributors

vanceleon avatar adfaris avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.