陈德本 4 anni fa
parent
commit
74879d57eb
2 ha cambiato i file con 132 aggiunte e 26 eliminazioni
  1. 46 26
      site.php
  2. 86 0
      wandoujia.php

+ 46 - 26
site.php

@@ -8,15 +8,26 @@ use QL\QueryList;
 
 require_once('vendor/autoload.php');
 
-$domain = $_POST['domain'];
-$page = $_POST['page'];
-$word = $_POST['word'];
+$domain = $_REQUEST['domain'];
+$page = $_REQUEST['page']?:2;
+$word = $_REQUEST['word'];
 $ql = QueryList::getInstance();
 //$ql->use(Baidu::class);
 //or Custom function name
-$ql->use(Baidu::class, 'baidu', "M");
+$ql->use(Baidu::class, 'baidu');
 $baidu = $ql->baidu(10);
-$str = "site:" . $domain;
+
+
+//$searcher = $baidu->search('site:csdn.net');
+//$count = $searcher->getCount(); // 获取搜索结果总条数
+//$data = $searcher->page(1,true);
+//print_r($data);
+//die();
+//$data = $searcher->page(2);
+
+//$searcher = $baidu->search('php');
+//$countPage = 2;//$searcher->getCountPage();  // 获取搜索结果总页数
+$str = "site:".$domain ;
 if ($word) {
     $origin_str = [';', ';', ',', ',', ' ', "\r\n"];
     $des_str = [',', ',', ',', ',', ',', ','];
@@ -30,31 +41,46 @@ $header = [[
 ]];
 $p = 0;
 $spreadsheet = new Spreadsheet();
-foreach ($word as $item) {
-    $str = $str . " " . $item;
+if (!$word){
     $searcher = $baidu->search($str);
-    $count = $searcher->getCount();
-    $page = $page > $count ? $count : $page;
     $result = [];
     for ($i = 1; $i <= $page; $i++) {
-        $data = $searcher->page($i, true);
+        $data = $searcher->page($i,true);
         $data = json_decode(json_encode($data), true);
         $data = array_filter($data);
         $result = array_merge($result, $data);
     }
     $act_sheet = $spreadsheet->getActiveSheet();
     $result = array_merge($header, $result);
-    $title = "关键词:" . $item;
-    if ($p == 0) {
-        $act_sheet->setTitle($title);
-        $act_sheet->fromArray($result);
-    } else {
-        $sheet = new Worksheet();
-        $sheet->setTitle($title);
-        $sheet->fromArray($result);
-        $spreadsheet->addSheet($sheet);
+    $act_sheet->fromArray($result);
+
+}else{
+    foreach ($word as $item) {
+        $str = $str . " " . $item;
+        $searcher = $baidu->search($str);
+        $count = $searcher->getCount();
+        $page = $page > $count ? $count : $page;
+        $result = [];
+        for ($i = 1; $i <= $page; $i++) {
+            $data = $searcher->page($i, true);
+            $data = json_decode(json_encode($data), true);
+            $data = array_filter($data);
+            $result = array_merge($result, $data);
+        }
+        $act_sheet = $spreadsheet->getActiveSheet();
+        $result = array_merge($header, $result);
+        $title = "关键词:" . $item;
+        if ($p == 0) {
+            $act_sheet->setTitle($title);
+            $act_sheet->fromArray($result);
+        } else {
+            $sheet = new Worksheet();
+            $sheet->setTitle($title);
+            $sheet->fromArray($result);
+            $spreadsheet->addSheet($sheet);
+        }
+        $p++;
     }
-    $p++;
 }
 try {
 
@@ -74,9 +100,3 @@ try {
 }
 
 
-//$data = $searcher->page(1,true);
-//$data=json_decode(json_encode($data),true);
-//print_r($data);
-
-
-

+ 86 - 0
wandoujia.php

@@ -0,0 +1,86 @@
+<?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();
+}