模糊抓取优化
This commit is contained in:
@@ -328,20 +328,22 @@ class BrandSeriesService
|
|||||||
// 执行抓取
|
// 执行抓取
|
||||||
$crawlService = new CrawlService();
|
$crawlService = new CrawlService();
|
||||||
|
|
||||||
//懂车帝模糊搜索返回车系地址
|
//懂车帝模糊搜索返回车系地址|单个车系id抓取
|
||||||
$href = $crawlService->modelSearch($keyword);
|
$href = $crawlService->modelSearch($keyword);
|
||||||
$seriesId = $this->extractSeriesId($href); //懂车帝车系id
|
$seriesId = $this->extractSeriesId($href); //懂车帝车系id
|
||||||
|
|
||||||
if (empty($seriesId)) { //没有抓取到懂车帝系列id时,按关键词为品牌名抓取所有的系列名
|
// if (empty($seriesId)) { //没有抓取到懂车帝系列id时,按关键词为品牌名抓取所有的系列名
|
||||||
$crawlSeries = $crawlService->brandSeries($keyword);
|
// $crawlSeries = $crawlService->brandSeries($keyword);
|
||||||
}
|
// }
|
||||||
|
//按关键词为品牌名抓取所有的系列名
|
||||||
|
$crawlSeries = $crawlService->brandSeries($keyword);
|
||||||
|
|
||||||
if (empty($seriesId) && empty($crawlSeries)) {
|
if (empty($seriesId) && empty($crawlSeries)) {
|
||||||
throw new \Exception('抓取失败,未找到该系列车型');
|
throw new \Exception('抓取失败,未找到该系列车型');
|
||||||
}
|
}
|
||||||
|
|
||||||
$brandSerieses = [];
|
$brandSerieses = [];
|
||||||
if(empty($seriesId) && !empty($crawlSeries)){ //关键词为品牌名时抓取所有车系的懂车帝id
|
if(empty($seriesId) && !empty($crawlSeries) || count($crawlSeries)>1){ //关键词为品牌名时抓取所有车系的懂车帝id
|
||||||
$href = $crawlService->modelSearch($crawlSeries[0]);
|
$href = $crawlService->modelSearch($crawlSeries[0]);
|
||||||
$seriesId = $this->extractSeriesId($href); //懂车帝车系id
|
$seriesId = $this->extractSeriesId($href); //懂车帝车系id
|
||||||
//抓取品牌与系列
|
//抓取品牌与系列
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class CrawlService
|
|||||||
{
|
{
|
||||||
public function brandSeries($brand)
|
public function brandSeries($brand)
|
||||||
{
|
{
|
||||||
$url = "https://www.dongchedi.com/search?currTab=6&keyword=".$brand;
|
$url = "https://www.dongchedi.com/search?currTab=6&keyword=".$brand.'&from=search_tab_er&api_param={"en_qc":+0}';
|
||||||
$ql = QueryList::get($url );
|
$ql = QueryList::get($url );
|
||||||
$series = [];
|
$series = [];
|
||||||
$ql->find('div.card-name')->texts()->map(function($item) use(&$series) {
|
$ql->find('div.card-name')->texts()->map(function($item) use(&$series) {
|
||||||
|
|||||||
Reference in New Issue
Block a user