wandoujia.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. require 'vendor/autoload.php';
  3. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  4. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  5. use QL\QueryList;
  6. $urls=getList();
  7. $apps=[];
  8. foreach ($urls as $url) {
  9. preg_match("/\d+/",$url,$catid);
  10. for ($i=1;$i<20;$i++){
  11. $data=getPages($catid[0],$i);
  12. if ($data){
  13. $apps=array_merge($apps,$data);
  14. }
  15. }
  16. }
  17. $spreadsheet = new Spreadsheet();
  18. try {
  19. $title="豌豆荚";
  20. $sheet = $spreadsheet->getActiveSheet();
  21. $sheet->setTitle($title);
  22. $sheet->fromArray($apps);
  23. $writer = new Xlsx($spreadsheet);
  24. $writer->save('/www/ai/'.$title.".xlsx");
  25. $spreadsheet->disconnectWorksheets();
  26. } catch (\PhpOffice\PhpSpreadsheet\Exception $e) {
  27. }
  28. function getPages($catid,$page){
  29. echo "正在处理:$catid\t$page".PHP_EOL;
  30. $url="https://www.wandoujia.com/wdjweb/api/category/more?catId={$catid}&subCatId=0&page=$page&ctoken=35CLqdFYoYWt80ByPrajl22L";
  31. $html=json_decode(file_get_contents($url),true)['data']['content'];
  32. return getListByHtml($html);
  33. }
  34. function getListByHtml($html){
  35. $rules = array (
  36. 'title' =>
  37. array (
  38. 0 => 'h2>a',
  39. 1 => 'text',
  40. ),
  41. 'link' =>
  42. array (
  43. 0 => 'h2>a',
  44. 1 => 'href',
  45. ),
  46. );
  47. $data=(new QL\QueryList)->html($html)->rules($rules)->range('.card')->queryData();
  48. foreach ($data as &$datum) {
  49. preg_match("/\d+/",$datum['link'],$appid);
  50. $appid=$appid[0];
  51. $datum['down_url']="https://www.wandoujia.com/apps/{$appid}/download/dot?ch=detail_normal_dl";
  52. }
  53. return $data;
  54. }
  55. function getFirstAppList($url){
  56. $rules = array (
  57. 'title' =>
  58. array (
  59. 0 => 'h2>a',
  60. 1 => 'text',
  61. ),
  62. 'link' =>
  63. array (
  64. 0 => 'h2>a',
  65. 1 => 'href',
  66. ),
  67. );
  68. $data = QueryList::get($url)->rules($rules)->range('.app-box>.card')->queryData();
  69. return $data;
  70. }
  71. function getList(){
  72. $data = (new QL\QueryList)->get('https://www.wandoujia.com/category/app?pos=w/crumb/appcategory')->find('.cate-link')->attrs('href');
  73. return $data->all();
  74. }