|
@@ -0,0 +1,62 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+
|
|
|
|
|
+use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
|
|
+use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
|
|
|
+use QL\Ext\Baidu;
|
|
|
|
|
+use QL\QueryList;
|
|
|
|
|
+
|
|
|
|
|
+require_once('vendor/autoload.php');
|
|
|
|
|
+
|
|
|
|
|
+$domain = $_POST['domain'];
|
|
|
|
|
+$page = $_POST['page'];
|
|
|
|
|
+$word = $_POST['word'];
|
|
|
|
|
+$ql = QueryList::getInstance();
|
|
|
|
|
+$ql->use(Baidu::class);
|
|
|
|
|
+//or Custom function name
|
|
|
|
|
+$ql->use(Baidu::class, 'baidu');
|
|
|
|
|
+$baidu = $ql->baidu(10);
|
|
|
|
|
+$str = "site:" . $domain;
|
|
|
|
|
+if ($word) {
|
|
|
|
|
+ $str = $str . " " . $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 = json_decode(json_encode($data), true);
|
|
|
|
|
+ $result=array_merge($result,$data);
|
|
|
|
|
+}
|
|
|
|
|
+$header = [[
|
|
|
|
|
+ '标题',
|
|
|
|
|
+ '链接',
|
|
|
|
|
+]];
|
|
|
|
|
+$result=array_merge($header,$result);
|
|
|
|
|
+$spreadsheet = new Spreadsheet();
|
|
|
|
|
+try {
|
|
|
|
|
+ $title="site数据";
|
|
|
|
|
+ $sheet = $spreadsheet->getActiveSheet();
|
|
|
|
|
+ $sheet->setTitle($title);
|
|
|
|
|
+ $sheet->fromArray($result);
|
|
|
|
|
+ $writer = new Xlsx($spreadsheet);
|
|
|
|
|
+ header("Pragma: public");
|
|
|
|
|
+ header("Expires: 0");
|
|
|
|
|
+ header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
|
|
|
|
|
+ header("Content-Type:application/force-download");
|
|
|
|
|
+ header("Content-Type:application/vnd.ms-execl");
|
|
|
|
|
+ header("Content-Type:application/octet-stream");
|
|
|
|
|
+ header("Content-Type:application/download");
|
|
|
|
|
+ header('Content-Disposition:attachment;filename="'.$title.'.xlsx"');
|
|
|
|
|
+ header("Content-Transfer-Encoding:binary");
|
|
|
|
|
+ $writer->save('php://output');
|
|
|
|
|
+ $spreadsheet->disconnectWorksheets();
|
|
|
|
|
+} catch (\PhpOffice\PhpSpreadsheet\Exception $e) {
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+//$data = $searcher->page(1,true);
|
|
|
|
|
+//$data=json_decode(json_encode($data),true);
|
|
|
|
|
+//print_r($data);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|