9gag-scraper 中文文档教程

发布于 7年前 浏览 28 项目主页 更新于 3年前

9gag-scraper

Build Status

从 9GAG 网站抓取数据

Installation

npm install 9gag-scraper --save

Usage

var gagScraper = require('9gag-scraper')

Scrape data from a 9GAG section

new gagScraper("trending").getGags(function (error, data) {

    console.log(data.count); // Total posts returned
    console.log(data.gags); // posts object ( array of posts )

    console.log(data.gags[0].id); // 9GAG post ID
    console.log(data.gags[0].url); // 9GAG post URL
    console.log(data.gags[0].title); // 9GAG post title
    console.log(data.gags[0].image); // 9GAG post image link

});

// You can also pass in any valid section you want to scrape from ( Defaults to 'hot' )
new gagScraper("fresh").getGags(function (error, data) {
});

new gagScraper("meme").getGags(function (error, data) {
});

NSFW section scraping won't work as it requires users to login to view the content.

To get a random post

new gagScraper().getRandom(function (error, data) {
    console.log(data.id); // 9GAG post ID
    console.log(data.url); // 9GAG post URL
    console.log(data.title); // 9GAG post title
    console.log(data.image); // 9GAG post image link
});

new gagScraper("random").getGags(function (error, data) {
});

Tests

npm test

9gag-scraper

Build Status

Scrape data from 9GAG website

Installation

npm install 9gag-scraper --save

Usage

var gagScraper = require('9gag-scraper')

Scrape data from a 9GAG section

new gagScraper("trending").getGags(function (error, data) {

    console.log(data.count); // Total posts returned
    console.log(data.gags); // posts object ( array of posts )

    console.log(data.gags[0].id); // 9GAG post ID
    console.log(data.gags[0].url); // 9GAG post URL
    console.log(data.gags[0].title); // 9GAG post title
    console.log(data.gags[0].image); // 9GAG post image link

});

// You can also pass in any valid section you want to scrape from ( Defaults to 'hot' )
new gagScraper("fresh").getGags(function (error, data) {
});

new gagScraper("meme").getGags(function (error, data) {
});

NSFW section scraping won't work as it requires users to login to view the content.

To get a random post

new gagScraper().getRandom(function (error, data) {
    console.log(data.id); // 9GAG post ID
    console.log(data.url); // 9GAG post URL
    console.log(data.title); // 9GAG post title
    console.log(data.image); // 9GAG post image link
});

new gagScraper("random").getGags(function (error, data) {
});

Tests

npm test

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文