Code Monkey home page Code Monkey logo

dugtrio's Introduction

Dugtrio

Dugtrio is Object Oriented Web Scraping.

Dugtrio uses

  • Puppeteer for scraping,
  • Knex as SQL Query Builder.(default RDBMS is MySQL)

Installation

npm install dugtrio

Basic Usage

Define scraping target page detail:

const Dugtrio = require("dugtrio");
const BaseModel = Dugtrio.BaseModel;

class TwitterUser extends BaseModel {
  constructor() {
    super();
    this.url = 'https://twitter.com/(:username)?lang=ja',
    this.primary = "username"
    this.columns = {
      'followersCount': function() { return Array.from(document.getElementsByTagName('a')).filter(e => e.dataset['nav'] === 'followers')[0].getElementsByClassName('ProfileNav-value')[0].innerText.replace(',', ''); },
      'followingsCount': function() { return Array.from(document.getElementsByTagName('a')).filter(e => e.dataset['nav'] === 'following')[0].getElementsByClassName('ProfileNav-value')[0].innerText.replace(',', ''); },
    }
  }
}

const Diglett = Dugtrio.Diglett;
const username = 'Masayukiii';
(async(username) => {
  instance = new TwitterUser
  diglett = new Diglett(instance);
  await diglett.fetch(username).then(async(data) =>{ console.log(data) });
})(username);

Advanced Usage

generate template

I Strongrly recommend use this template, it supports variaus option.

npm run dugtrio generate

how to save data

update database(MySQL) config on config/default.js.

{
  "db":{
    "host": "127.0.0.1",
    "user": "root",
    "password": "",
    "charset": "utf8",
    "database": "Dugtrio
  }
}

after fetching, you can save them. (Default data type is JSON.)

(async(username) => {
  instance = new TwitterUser
  diglett = new Diglett(instance);
  await diglett.fetch(username).then(async(data) =>{ await instance.save(data) });
})(username);

how to collect a lot of data all at once.

dugtrio supports to get seed data. (You know user list is oftern separate. So you have to get them to access page like user profile.)

BestPractice

I will introduce best practice code using dugtrio.

Option

next time

How to use CLI

suprisingly, dugtorio supports cli. so you can scrap on your terminal.

default useage example

Option

with -d, save data with -j, output to data/json/

caution

about time sleep

default time sleep is about 5s. This behaviour is not like human. if you want to change it. you can edit Diglett code.

WARNING: you have to remember that Scraping so many times in short term is evil, I dont have any responsiblities about this.

about login

if you want to login fetch more detail info, be careful to use fetch method many times because many login and logout action in short time is so strange.

about database

dugrorio creates database, and table, columns by your definition automatically If you use BaseModel init method. And data type of primary key is string (with index), the others's data type is text. I guess you think it is bad, I agree you opinion. But it is so tired to define data type of each elements and scraping contens is text base.

dugtrio's People

Contributors

s-ekai avatar

Stargazers

Shoji Yokomi avatar

Watchers

 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.