Commit 213d3c50 authored by hj's avatar hj

更新提交

parent 8e6c7836
...@@ -67,6 +67,8 @@ class CheMenuCommand extends Command ...@@ -67,6 +67,8 @@ class CheMenuCommand extends Command
break; break;
case 'product': case 'product':
$service->productPage($params); $service->productPage($params);
case 'updateCategoryDesc':
$service->updateAllCategoryDesc($params);
default: default:
} }
} }
......
...@@ -56,6 +56,27 @@ class CheMenuApiService extends PlatformAbstractService ...@@ -56,6 +56,27 @@ class CheMenuApiService extends PlatformAbstractService
} }
} }
public function updateCategoryDesc($categoryName, $content)
{
try{
$response = $this->getPostClient($this->yybaoApiUrl.'/webpage/chemenu/updateCategoryDesc',
[
'categoryName' => $categoryName,
'content' => $content
], []);
return $this->returnResponse($response);
}catch(\Throwable $exception){
if(preg_match('/\{(?<response>[\s\S]*?)\}/i', $exception->getMessage(), $response)){
$response = json_decode('{'.$response['response'].'}', true);
if($response && $response['status'] == 429){
sleep(60);
$this->updateCategoryDesc($categoryName, $content);
}
}
$this->requestError($exception);
}
}
public function saveProduct($productContent) public function saveProduct($productContent)
{ {
try{ try{
......
...@@ -46,6 +46,49 @@ class CheMenuService ...@@ -46,6 +46,49 @@ class CheMenuService
} }
} }
public function updateAllCategoryDesc()
{
$responseHtml = $this->apiService->getAllCatetgory();
if($responseHtml){
$categoryDivRegx = '/<dt><span[\s]*?style=[\\\'|\"][\s\S]+?[\\\'|\"]>(?<categoryH1>[\s\S]+?)<\/span>[\s\S]*?<dd>(?<category>[\s\S]+?)<\/dd>/i';
preg_match_all($categoryDivRegx, $responseHtml,$categoryHtml);
if($categoryHtml){
foreach($categoryHtml['categoryH1'] as $key => $h1){
if(!empty($categoryHtml['category'][$key])){
preg_match_all('/<a[\s]*?href=[\\\'|\"](?<href>[\s\S]+?)[\\\'|\"]>(?<categoryName>[\s\S]+?)<\/a>/i', $categoryHtml['category'][$key],$categoryList);
if(!empty($categoryList)){
foreach($categoryList['categoryName'] as $k => $category){
$pageUrl = $categoryList['href'][$k];
$responseHtml = $this->apiService->getPage($pageUrl);
if($responseHtml){
if(preg_match('/<span[\s]*?class=[\\\'|\"]caption-subject font-blue-sharp bold[\\\'|\"]>Sorry ! You visit too frequently, please complete validation[\s\S]*?<\/span><\/h2>/i', $responseHtml)){
SimpleLogs::writeLog('遇到反爬系统', 'chemenu info', 'info');
$jobContent = [
'params' => ['url' => $pageUrl],
'consumer' => __CLASS__,
'method' => 'categoryPage'
];
$this->apiService->pushQueue($jobContent,'chemenu_category_page');
break;
}
SimpleLogs::writeLog('开始分析分类页面数据', 'chemenu info', 'info');
$titleDivRegx = '/<div[\s]*?class=[\\\'|\"]cate_desc[\\\'|\"]>[\S\s]*<h2[\s]*?class=[\\\'|\"]desc_title[\\\'|\"]>(?<title>[\s\S]+?)<\/h2>[\s\S]*?<p[\s]*?class=[\\\'|\"]desc_content[\\\'|\"]>(?<content>[\s\S]*?)<\/p>/i';
preg_match($titleDivRegx, $responseHtml,$titleHtml);
if($titleHtml){
$this->apiService->updateCategoryDesc($category, $titleHtml['content']);
}
}
}
}
}
sleep(60);
}
}
return true;
}
}
public function categoryPage($url) public function categoryPage($url)
{ {
try{ try{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment