liang256 / laravel-crawler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

About Laravel-Crawler

Features

  • Facebook OAuth login
  • AstroCrawler is a tool to crawl this website's daily astro fortunes

Usage of AstroCrawlerService

It is very simpler to use.

This sample crawl today's fortune of 12 astros and return a collection of AstroFortune models.

$service = new AstroCrawlerService();
$models = $service->crawl();

To save them into DB, you can achieve it by easily using each provided by collection.

$models->each(funciton ($model) {
    $model->save();
});

setType

There are 3 types of this crawler

  1. fortune of a date in this week
  2. fortune of this week
  3. fortune of this month

To set the type of fortune to crawl

$models = $service->setType(2)->crawl();

setAstros & setAstro

By default, this service will crawl all 12 astros, but we can specific which astros to crawl by these 2 functions.

AstroCrawlerService provides const variables to easily choose astros.

use AstroCrawlerService as ACS
$models = $service->setType(2)->setAstro(ACS::GEMINI)->crawl();
$models = $service->setType(2)->setAstros([0, 2, 4])->crawl();

setDate

This function only be useful when "fortune of a date" (type 0)

$date = today()->format('Y-m-d');
$models = $service->setType(0)->setDate($date)->crawl();

select

Select what columns to crawl like SQL language. By default, this service will crawl all 4 columns

general: 整體運勢
love: 愛情運勢
career: 事業運勢
wealth: 財運運勢

$models = $service->setType(2)->select(['love', 'general'])->crawl();

About


Languages

Language:PHP 72.4%Language:Blade 27.1%Language:Shell 0.5%