11
22## Usage: Depend On The PHPCreeper Application Framework
3- Now, let's do the same job based on the Application Framework:
3+ Now, let's do the same job based on the PHPCreeper Application Framework:
44
55
66#### * Step-1:Download PHPCreeper-Application Framework*
@@ -32,27 +32,28 @@ php Application/Sbin/Creeper
3232
3333#### * Step-4:Create One Application*
3434
35- 1、Create one spider application named ** github ** :
35+ 1、Create one spider application named ** weather ** :
3636```
37- php Application/Sbin/Creeper make github --en
37+ php Application/Sbin/Creeper make weather --en
3838```
3939
40402、The complete execution process looks like this:
41- ![ AppAssistant] ( /Image/AppGithubEnglish.png )
4241
43- As matter of fact, we have accomplished all the jobs at this point,
44- you just need to run ` php github.php start ` to see what has happened,
45- but you still need to finish the rest step of the work if you wanna
42+ ![ AppWeather2English] ( /Image/AppWeather2English.png )
43+
44+ In fact, we have done all the jobs at this point,
45+ now you just need to run ` php weather.php start ` to see what has happened,
46+ but you still need to finish the rest step of the work if you want to
4647do some elaborate work or jobs.
4748
4849#### * Step-5:Business Configuration*
49501、Switch to the application config direcory:
5051```
51- cd Application/Spider/Github /Config/
52+ cd Application/Spider/Weather /Config/
5253```
53542、Edit the global config file named ** global.php** :
5455```
55- Normally , there is no need to change this file unless you wanna create a new global sub-config file
56+ Basically , there is no need to change this file unless you want to create a new global sub-config file
5657```
57583、Edit the global sub-config file named ** database.php** :
5859``` php
@@ -62,7 +63,7 @@ return [
6263 'host' => '127.0.0.1',
6364 'port' => 6379,
6465 'database' => 0,
65- 'prefix' => 'Github ',
66+ 'prefix' => 'Weather ',
6667 ],
6768];
6869```
@@ -74,7 +75,7 @@ return [
7475 'host' => '127.0.0.1',
7576 'port' => 6379,
7677 'database' => 0,
77- 'prefix' => 'Github ',
78+ 'prefix' => 'Weather ',
7879 ]],
7980];
8081```
@@ -95,9 +96,9 @@ return array(
9596
9697 //whether to start the given worker(s) instance or not(optional, default `true`)
9798 'start' => array(
98- 'GithubProducer ' => true,
99- 'GithubDownloader ' => true,
100- 'GithubParser ' => true,
99+ 'AppProducer ' => true,
100+ 'AppDownloader ' => true,
101+ 'AppParser ' => true,
101102 ),
102103
103104 //global task config
@@ -110,7 +111,7 @@ return array(
110111
111112 //specifies the max number of connections each downloader process can connect to the parser
112113 //(optional, default `1`, minimum value 1, maximum value 1000)
113- // 'max_connections' => 1,
114+ 'max_connections' => 1,
114115
115116 //set the max number of the request for each socket connection,
116117 //if the cumulative number of socket requests exceeds the max number of requests,
@@ -213,12 +214,13 @@ return array(
213214
214215 //set the initialized task, support both Single-Task and Multi-Task
215216 'task_init' => array(
216- 'url' => ' https://github.com/search?q=stars:%3E1&s=stars&type=Repositories' ,
217+ 'url' => " https://forecast.weather.gov/MapClick.php?lat=47.4113&lon=-120.5563" ,
217218
218219 //please refer to the "How to set extractor rule" section for details
219220 "rule" => array(
220- 'title' => ['ul.repo-list div.f4.text-normal > a', 'text'],
221- 'stars' => ['ul.repo-list div.mr-3:nth-of-typ(1) > a', 'text'],
221+ 'period' => ['#seven-day-forecast-container ul li p.period-name', 'text'],
222+ 'weather' => ['#seven-day-forecast-container ul li p.short-desc', 'text'],
223+ 'temperature' => ['#seven-day-forecast-container ul li p.temp', 'text'],
222224 ),
223225
224226 //set rule name which will be set to `md5($task_id)` if leave it empty
@@ -305,20 +307,22 @@ public function onDownloaderReload($downloader)
305307{
306308}
307309
310+ public function onDownloaderConnectToParser($connection)
311+ {
312+ }
313+
308314public function onDownloaderMessage($downloader, $parser_reply)
309315{
310316}
311317
312318public function onDownloadBefore($downloader, $task)
313319{
314320 //here we can reset the $task and then return it
315- //$task = [...];
316321 //return $task;
317322
318323 //here we can change the context parameters when creating a http request
319- //$downloader->httpClient->setConnectTimeout(3 );
324+ //$downloader->httpClient->setConnectTimeout(5 );
320325 //$downloader->httpClient->setTransferTimeout(10);
321- //$downloader->httpClient->setProxy('http://180.153.144.138:8800');
322326 //$downloader->httpClient->disableSSL();
323327}
324328
@@ -335,6 +339,10 @@ public function onDownloadAfter($downloader, $download_data, $task)
335339public function onDownloadFail($downloader, $error, $task)
336340{
337341}
342+
343+ public function onTaskEmpty($downloader)
344+ {
345+ }
338346```
3393473、Write business callback for AppParser:
340348``` php
@@ -383,13 +391,13 @@ it can be distributed or deployed separately.
383391
3843921、Or Global Startup:
385393```
386- php github .php start
394+ php weather .php start
387395```
388396
3893972、Or Single Startup:
390398```
391- php Application/Spider/Github/ AppProducer.php start
392- php Application/Spider/Github/ AppDownloader.php start
393- php Application/Spider/Github/ AppParser.php start
399+ php Application/Spider/Weather/Start/ AppProducer.php start
400+ php Application/Spider/Weather/Start/ AppDownloader.php start
401+ php Application/Spider/Weather/Start/ AppParser.php start
394402```
395403
0 commit comments