Coder Social home page Coder Social logo

waynechang65 / ptt-crawler Goto Github PK

View Code? Open in Web Editor NEW
20.0 2.0 10.0 665 KB

ptt-crawler is a web crawler module designed to scarpe data from Ptt.

License: MIT License

JavaScript 100.00%
ptt crawler scraping webcrawler spider scraper javascript web-crawler nodejs

ptt-crawler's Introduction

npm npm Npm package total downloads Build Status GitHub

ptt-crawler

ptt-crawler 是一個專門用來爬批踢踢(Ptt)各版資料的爬蟲模組。

ptt-crawler is a web crawler module designed to scarpe data from Ptt.

前言(Overview)

批踢踢(Ptt)是台灣最大的BBS(Bulletin Board System),也是許多台灣大數據分析常參考的資料庫。 不過,大多數Ptt爬蟲都是用python程式所寫。 本人為了在Node.js上爬批踢踢(Ptt)的資料,乾脆就自己用javascript打造一個簡單的爬蟲模組,並且分享給大家使用。

Ptt is the most famous and biggest BBS(Bulletin Board System) in Taiwan and also an import reference database for big data analysis. However, most of ptt crawler modules are written by python.
In order to scrape data from Ptt by Node.js, I just create a simple ptt crawler module by javascript and share it to everyone to use.

這個爬蟲模組能做什麼事? (What can it do ?)

  • 批踢踢(Ptt)任意的版上資料
    Scarping posts of any board on Ptt boards
  • 可以爬多頁資料
    Support to scrape pages in one time
  • 爬資料時,可選擇是否忽略置底文
    Support to skip fixed bottom posts
  • 爬的資料以單一帖發文為單位,其中包含該帖的超連結、推文數、主題、作者名稱、發文日期以及是否被標記(Mark)等
    Scraped posts contain hyperlinks, likes, titles, authors, dates and the status of posts(like be marked...)
  • 針對發文,可選擇是否要爬所有內文(含留言)
    All of the scraped data are optional

如何在您的專案使用? (How to use it in your project ?)

  • 利用 npm 套件進行下載
    Use npm to install
npm install --save @waynechang65/ptt-crawler
  • 在您的專案環境中,引用 @waynechang65/ptt-crawler模組。
    Include @waynechang65/ptt-crawler package in your project
const ptt_crawler = require('@waynechang65/ptt-crawler');
  • 接下來,用async函式包含下面幾行程式就搞定了。
    Add programs below in an async function in your project
// *** Initialize *** 
await ptt_crawler.initialize();

// *** GetResult  ***
let ptt = await ptt_crawler.getResults({
    board: 'PokemonGO',
    pages: 3,
    skipPBs: true,
    getContents: true
}); // Ptt PokemonGO board, 3 pages, skip fixed bottom posts, scrape content of posts

// *** Close      ***
await ptt_crawler.close();
  • 爬完的資料會透過函式 getResults() 回傳一個物件,裏面各陣列放著爬完的資料,結構如下:
    Scraped data will be returned with an object by getResults() function, it shows below.
{ titles[], urls[], rates[], authors[], dates[], marks[], contents[] }

如何跑範例程式? (How to run the example ?)

  • 從GitHub下載ptt-crawler專案程式
    Clone ptt-crawler from GitHub
git clone https://github.com/WayneChang65/ptt-crawler.git
  • 在ptt-crawler專案環境中,下載必要模組。
    Install dependencies in the cloned ptt-crawler folder
npm install
  • 透過 npm 直接使用以下指令。(實際範例程式在 ./examples/demo.js)
    Run it with npm. (the demo example is in ./examples/demo.js)
npm start

image
image

基本函式 (Base Methods)

  • initialize(): 初始化物件, initialize ptt-crawler object
  • getResults(options): 開始爬資料, scrape data

options.board: 欲爬的ptt版名, board name of ptt
options.pages: 要爬幾頁, pages
options.skipPBs: 是否忽略置底文, skip fix bottom posts
options.getContents: 是否爬內文(會花費較多時間), scrape contents

  • close(): 關閉物件, close ptt-crawler object

參考網站 (Reference)

貢獻一己之力 (Contribution)

ptt-crawler 雖然是一個小模組,但本人還是希望這個專案能夠持續進步!若有發現臭蟲(bug)或問題,請幫忙在Issue留言告知詳細情形。
歡迎共同開發。歡迎Fork / Pull Request,謝謝。:)

Even though ptt-crawler is a small project, I hope it can be improving. If there is any issue, please comment and welcome to fork and send Pull Request. Thanks. :)

ptt-crawler's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ptt-crawler's Issues

Demo程式卡住

ptt傳說對決遊戲版的名稱,由RealmOfValor改為ArenaOfValor,造成跑

npm run start

進行demo程式執行,出現找不到網頁而卡住。(404)

Close()前,無法連續getResult()

由於.initialize()完之後,只能進行一次getResults(),只能爬一次結果。
如果要連續爬,就必須Close()。然後一直重覆initialize()及Close(),
明顯效率較差。
理應initialize()一次後,可以連續getResults(),連續爬,爬到開心之後,再Close()。
如此一來,效率最佳!

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.