File tree Expand file tree Collapse file tree 3 files changed +44
-10
lines changed Expand file tree Collapse file tree 3 files changed +44
-10
lines changed Original file line number Diff line number Diff line change 1919foreach ($ dir as $ key => $ value ) {
2020 $ spider .= PHP_EOL . $ key . " : " . $ value . PHP_EOL ;
2121}
22+ $ dlc =PHP_EOL .
23+ "
24+ \e[33m
25+ _ooOoo_
26+ o8888888o
27+ 88 \" . \"88
28+ (| -_- |)
29+ O\ = /O
30+ ____/`---'\____
31+ .' \\| |// `.
32+ / \\||| : |||// \
33+ / _||||| -:- |||||_ \
34+ | | \\\ - /'| | |
35+ | \_| `\`---'// |_/ |
36+ \ .-\__ `-. -'__/-. /
37+ ___`. .' /--.--\ `. .'___
38+ . \"\" '< `.___\_<|>_/___.' _> \\
39+ | | : `- \`. ;`. _/; .'/ / .' ; |
40+ \ \ `-. \_\_`. _.'_/_/ -' _.' /
41+ ===`-.`___`-.__\ \___ /__.-'_.'_.-'===
42+ `=--=-'
43+
44+ \033[0m\ " .PHP_EOL ;
2245$ print = "
23- =============================
24- PHP Images Spider "
25- . $ spiderCore ->eol ($ spider ).
26- "Chenjinyi:https://github.com/Chenjinyi
27- =============================
46+ ====================================================
47+ \033[33m PHP Images Spider \033[0m " .
48+ "\033[34m " .$ spiderCore ->eol ($ spider )."\033[0m " .
49+ "
50+ \033[33m Chenjinyi:https://github.com/Chenjinyi \033[0m
51+ ====================================================
2852 " . PHP_EOL .
2953 "请输入你选择的爬虫: " ;
30- print_r ($ print );
54+ print_r ($ dlc . $ print );
3155$ input = trim (fgets (STDIN ));
3256
3357$ t1 = microtime (true );//记录运行时间
Original file line number Diff line number Diff line change @@ -86,7 +86,11 @@ public function user_input($string, $default)
8686 {
8787 print_r ($ string );
8888 $ input = trim (fgets (STDIN ));
89- if (empty ($ input )) return $ default ;
89+ if (empty ($ input )) {
90+ print_r ($ default .PHP_EOL );
91+ return $ default ;
92+ }
93+ print_r ($ input .PHP_EOL );
9094 return $ input ;
9195
9296 }
Original file line number Diff line number Diff line change @@ -23,17 +23,23 @@ class Pixabay
2323);
2424
2525;
26+
2627//获取数据
2728$ spiderCore ->init_dir ();
2829$ key = $ spiderCore ->check_api_file ('PixabayApiKey ' ) ?: die ("PixabayKey为空 " );//获取用户Key
2930$ q = $ spiderCore ->user_input ("请输入一个需要查询的字符串(不输入就随缘了): " ,RAND_KEYWORD [mt_rand (0 ,count (RAND_KEYWORD )-1 )]); //获取查询内容
30- print_r ($ q .PHP_EOL );//输出刚刚选择的
31- $ result = json_decode ($ result = $ spiderCore ->curl_get (PIXABAY_API_URL ."?key= " .$ key ."&q= " .$ q ,$ user_agent ));//通过Api得到数据
31+ $ per_page = $ spiderCore ->user_input ($ spiderCore ->eol ("每次最多尝试下载200张 " )."尝试爬取的图片数量(每页图片张数) " .$ spiderCore ->eol ("最终下载图片数量=(图片张数*多次执行的图片页数) " )."请输一页的图片数量3~200(默认为30): " ,30 ); //获取查询内容
32+ $ page = $ spiderCore ->user_input (PHP_EOL ."请输入获取的图片页数(默认为1): " ,1 ); //获取查询内容
33+
34+ $ result = json_decode ($ result = $ spiderCore ->curl_get (PIXABAY_API_URL ."?key= " .$ key ."&q= " .$ q ."&per_page= " .$ per_page ."&page= " .$ page ,$ user_agent ));//通过Api得到数据
3235$ images_arr =[];
3336foreach ($ result ->hits as $ images ){
3437 $ format =explode ('. ' ,$ images ->largeImageURL );
3538 array_push ($ images_arr ,["pixabay- " .$ images ->id .". " .$ format ['2 ' ]=>$ images ->largeImageURL ]);
3639}
3740$ dir_path =$ spiderCore ->new_dir_name ("pixabay- " .$ q );//生成保存路径
3841$ spiderCore ->image_save ($ images_arr ,$ dir_path );//下载图片
39- print_r ("成功下载: " .$ spiderCore ->images_number ($ dir_path )."张图片 " );
42+
43+
44+
45+ print_r ("文件夹现在有: " .$ spiderCore ->images_number ($ dir_path )."张图片 " );
You can’t perform that action at this time.
0 commit comments