| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- require 'vendor/autoload.php';
- use PhpOffice\PhpSpreadsheet\Spreadsheet;
- use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
- use QL\QueryList;
- $urls=getList();
- $apps=[];
- foreach ($urls as $url) {
- preg_match("/\d+/",$url,$catid);
- for ($i=1;$i<20;$i++){
- $data=getPages($catid[0],$i);
- if ($data){
- $apps=array_merge($apps,$data);
- }
- }
- }
- $spreadsheet = new Spreadsheet();
- try {
- $title="豌豆荚";
- $sheet = $spreadsheet->getActiveSheet();
- $sheet->setTitle($title);
- $sheet->fromArray($apps);
- $writer = new Xlsx($spreadsheet);
- $writer->save('/www/ai/'.$title.".xlsx");
- $spreadsheet->disconnectWorksheets();
- } catch (\PhpOffice\PhpSpreadsheet\Exception $e) {
- }
- function getPages($catid,$page){
- echo "正在处理:$catid\t$page".PHP_EOL;
- $url="https://www.wandoujia.com/wdjweb/api/category/more?catId={$catid}&subCatId=0&page=$page&ctoken=35CLqdFYoYWt80ByPrajl22L";
- $html=json_decode(file_get_contents($url),true)['data']['content'];
- return getListByHtml($html);
- }
- function getListByHtml($html){
- $rules = array (
- 'title' =>
- array (
- 0 => 'h2>a',
- 1 => 'text',
- ),
- 'link' =>
- array (
- 0 => 'h2>a',
- 1 => 'href',
- ),
- );
- $data=(new QL\QueryList)->html($html)->rules($rules)->range('.card')->queryData();
- foreach ($data as &$datum) {
- preg_match("/\d+/",$datum['link'],$appid);
- $appid=$appid[0];
- $datum['down_url']="https://www.wandoujia.com/apps/{$appid}/download/dot?ch=detail_normal_dl";
- }
- return $data;
- }
- function getFirstAppList($url){
- $rules = array (
- 'title' =>
- array (
- 0 => 'h2>a',
- 1 => 'text',
- ),
- 'link' =>
- array (
- 0 => 'h2>a',
- 1 => 'href',
- ),
- );
- $data = QueryList::get($url)->rules($rules)->range('.app-box>.card')->queryData();
- return $data;
- }
- function getList(){
- $data = (new QL\QueryList)->get('https://www.wandoujia.com/category/app?pos=w/crumb/appcategory')->find('.cate-link')->attrs('href');
- return $data->all();
- }
|