|
@@ -8,10 +8,6 @@ set_time_limit(0);
|
|
|
*/
|
|
*/
|
|
|
require_once('vendor/autoload.php');
|
|
require_once('vendor/autoload.php');
|
|
|
|
|
|
|
|
-use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
|
|
-use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
|
|
|
|
-use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
|
|
|
-use QL\QueryList;
|
|
|
|
|
|
|
|
|
|
//$ql = QueryList::get('https://www.baidu.com/s?wd=QueryList');
|
|
//$ql = QueryList::get('https://www.baidu.com/s?wd=QueryList');
|
|
|
//$titles = $ql->find('h3>a')->texts(); //获取搜索结果标题列表
|
|
//$titles = $ql->find('h3>a')->texts(); //获取搜索结果标题列表
|
|
@@ -79,116 +75,16 @@ if (!$wd) {
|
|
|
</html>
|
|
</html>
|
|
|
<?php
|
|
<?php
|
|
|
} else {
|
|
} else {
|
|
|
- error_reporting(0);
|
|
|
|
|
$origin_str = [';', ';', ',', ',', ' ', "\r\n"];
|
|
$origin_str = [';', ';', ',', ',', ' ', "\r\n"];
|
|
|
$des_str = [',', ',', ',', ',', ',', ','];
|
|
$des_str = [',', ',', ',', ',', ',', ','];
|
|
|
$wd = str_replace($origin_str, $des_str, $wd);
|
|
$wd = str_replace($origin_str, $des_str, $wd);
|
|
|
- $keys = explode(",", $wd);
|
|
|
|
|
$deep=$_REQUEST['deep']?:1;
|
|
$deep=$_REQUEST['deep']?:1;
|
|
|
- $result = $response = [];
|
|
|
|
|
- baidu($keys);
|
|
|
|
|
-// print_r($result);
|
|
|
|
|
-// die();
|
|
|
|
|
-
|
|
|
|
|
- $spreadsheet = new Spreadsheet();
|
|
|
|
|
- $sheet = $spreadsheet->getActiveSheet();
|
|
|
|
|
- $sheet->setTitle("为你推荐-相关搜索词");
|
|
|
|
|
- $row = 1;
|
|
|
|
|
- $sheet->setCellValue("A" . $row, "序号");
|
|
|
|
|
- $sheet->setCellValue("B" . $row, "关键词");
|
|
|
|
|
- $sheet->setCellValue("C" . $row, "相关搜索词");
|
|
|
|
|
- $row++;
|
|
|
|
|
- foreach ($result as $key => $item) {
|
|
|
|
|
- $sheet->setCellValue("A" . $row, $row - 1);
|
|
|
|
|
- $sheet->setCellValue("B" . $row, $item['key']);
|
|
|
|
|
- $sheet->setCellValue("C" . $row, $item['relatedWd']);
|
|
|
|
|
- $row++;
|
|
|
|
|
- }
|
|
|
|
|
- $styleArray = [
|
|
|
|
|
- 'alignment' => [
|
|
|
|
|
- 'horizontal' => Alignment::HORIZONTAL_CENTER,
|
|
|
|
|
- 'vertical' => Alignment::VERTICAL_CENTER,
|
|
|
|
|
- ],
|
|
|
|
|
- ];
|
|
|
|
|
- $sheet->getColumnDimension("A")->setWidth(14);
|
|
|
|
|
- $sheet->getColumnDimension("B")->setWidth(25);
|
|
|
|
|
- $sheet->getColumnDimension("C")->setWidth(25);
|
|
|
|
|
- $sheet->getStyle("A1:C" . $row)->applyFromArray($styleArray);
|
|
|
|
|
-
|
|
|
|
|
- $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="为你推荐-相关搜索词.xlsx"');
|
|
|
|
|
- header("Content-Transfer-Encoding:binary");
|
|
|
|
|
- $writer->save('php://output');
|
|
|
|
|
- $spreadsheet->disconnectWorksheets();
|
|
|
|
|
|
|
+ $cmd=sprintf("nohup /usr/local/php7.2/bin/php /home/wwwroot/wyt.phplife.net/cli.php %s %s > /home/wwwroot/wangyating.log &",$wd,$deep);
|
|
|
|
|
+ $str= shell_exec($cmd);
|
|
|
|
|
+ echo "任务提交成功!";
|
|
|
// echo "完成,总耗时".$second."秒";
|
|
// echo "完成,总耗时".$second."秒";
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
-function baidu($wds)
|
|
|
|
|
-{
|
|
|
|
|
- global $deep;
|
|
|
|
|
- for ($i = 0; $i < $deep; $i++) {
|
|
|
|
|
- if (!isset($_wds)) {
|
|
|
|
|
- $_wds = $wds;
|
|
|
|
|
- }
|
|
|
|
|
- $wds2 = [];
|
|
|
|
|
- foreach ($_wds as $wd) {
|
|
|
|
|
- $wds2 = array_merge($wds2, getRelatedKeywords($wd));
|
|
|
|
|
- }
|
|
|
|
|
- $_wds = $wds2;
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
-function getRelatedKeywords($wd)
|
|
|
|
|
-{
|
|
|
|
|
- global $response, $result;
|
|
|
|
|
- $searchUrl = "http://www.baidu.com/s?ie=UTF-8&rn=20&wd=%s";
|
|
|
|
|
-
|
|
|
|
|
- $url = sprintf($searchUrl, $wd);
|
|
|
|
|
- $rules = [
|
|
|
|
|
- 'json' => ['.c-tools', 'data-tools'],
|
|
|
|
|
- ];
|
|
|
|
|
- $ql = (new QL\QueryList)->get($url);
|
|
|
|
|
- $rt = $ql->rules($rules)->query()->getData();
|
|
|
|
|
- $rt = json_decode(json_encode($rt), true);
|
|
|
|
|
- $wds = [];
|
|
|
|
|
- foreach ($rt as $item) {
|
|
|
|
|
- $json = json_decode($item['json'], true);
|
|
|
|
|
- $baiduUrl = substr($json['url'], 30);
|
|
|
|
|
- if ($baiduUrl) {
|
|
|
|
|
- $_url = "https://sp2.baidu.com/8LUYsjW91Qh3otqbppnN2DJv/link?url=%s&query=%s&cb=jQuery110206243498231922682_1558178381142&data_name=recommend_common_merger_online&format=json&t=%s";
|
|
|
|
|
- $_url = sprintf($_url, $baiduUrl, $wd, time() . "000");
|
|
|
|
|
- $data = @file_get_contents($_url);
|
|
|
|
|
- $pat = "#1558178381142\((.*)\)#";
|
|
|
|
|
- preg_match($pat, $data, $arr);
|
|
|
|
|
- $data = json_decode($arr[1], true);
|
|
|
|
|
- if ($data['data'][0]['hintData']) {
|
|
|
|
|
- foreach ($data['data'][0]['hintData'] as $hintDatum) {
|
|
|
|
|
- if ($response[md5($item['wd'])]) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- foreach ($hintDatum['linkInfo'] as $item) {
|
|
|
|
|
- $response[md5($item['wd'])] = $item['wd'];
|
|
|
|
|
- $result[] = ['key' => $wd, 'relatedWd' => $item['wd']];
|
|
|
|
|
- $wds[] = $item['wd'];
|
|
|
|
|
- }
|
|
|
|
|
- foreach ($hintDatum['linkInfo2'] as $item) {
|
|
|
|
|
- $response[md5($item['wd'])] = $item['wd'];
|
|
|
|
|
- $result[] = ['key' => $wd, 'relatedWd' => $item['wd']];
|
|
|
|
|
- $wds[] = $item['wd'];
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-// print_r($data);die();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return $wds;
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
|
|
|