关键词抓取
This commit is contained in:
@@ -330,35 +330,59 @@ class BrandSeriesService
|
||||
|
||||
//懂车帝模糊搜索返回车系地址
|
||||
$href = $crawlService->modelSearch($keyword);
|
||||
$seriesId = $this->extractSeriesId($href);
|
||||
$seriesId = $this->extractSeriesId($href); //懂车帝车系id
|
||||
|
||||
if (empty($seriesId)) {
|
||||
if (empty($seriesId)) { //没有抓取到懂车帝系列id时,按关键词为品牌名抓取所有的系列名
|
||||
$crawlSeries = $crawlService->brandSeries($keyword);
|
||||
}
|
||||
|
||||
if (empty($seriesId) && empty($crawlSeries)) {
|
||||
throw new \Exception('抓取失败,未找到该系列车型');
|
||||
}
|
||||
|
||||
//抓取品牌与系列
|
||||
$brandSeries = $crawlService->crawlBrandSeries($seriesId);
|
||||
|
||||
|
||||
// 验证品牌是否存在
|
||||
$brand = Brand::where('brand_name', $brandSeries['brand'])->first();
|
||||
// 获取品牌信息
|
||||
$series = BrandSeries::where('series_name', $brandSeries['series'])->first();
|
||||
$result['brand'] = ['brand_name' => $brandSeries['brand'], 'exists' => $brand?1:0];
|
||||
if($brand){
|
||||
$result['brand']['id'] = $brand['id'];
|
||||
}
|
||||
$result['series'] = ['series_name' => $brandSeries['series'], 'exists' => $series?1:0];
|
||||
if($series){
|
||||
$result['series']['id'] = $series['id'];
|
||||
if(empty($result['brand']['id'])){
|
||||
$result['brand']['id'] = $series['brand_id'];
|
||||
$brandSerieses = [];
|
||||
if(empty($seriesId) && !empty($crawlSeries)){ //关键词为品牌名时抓取所有车系的懂车帝id
|
||||
$href = $crawlService->modelSearch($crawlSeries[0]);
|
||||
$seriesId = $this->extractSeriesId($href); //懂车帝车系id
|
||||
//抓取品牌与系列
|
||||
$brandSeries = $crawlService->crawlBrandSeries($seriesId);
|
||||
foreach ($crawlSeries as $item) {
|
||||
// $brandSerieses[] = $crawlService->brandSeries($keyword);
|
||||
$brandSerieses[] = ['brand' => $brandSeries['brand'], 'series' => $item];
|
||||
}
|
||||
}elseif (!empty($seriesId) && empty($crawlSeries)){
|
||||
//抓取品牌与系列
|
||||
$brandSerieses[] = $crawlService->crawlBrandSeries($seriesId);
|
||||
}
|
||||
|
||||
$result = [];
|
||||
try {
|
||||
//获取车型数据
|
||||
$result['model'] = $this->crawlSeriesModel($seriesId);
|
||||
foreach ($brandSerieses as $brandSeries) {
|
||||
$item = [];
|
||||
// 验证品牌是否存在
|
||||
$brand = Brand::where('brand_name', $brandSeries['brand'])->first();
|
||||
// 获取品牌信息
|
||||
$series = BrandSeries::where('series_name', $brandSeries['series'])->first();
|
||||
$item['brand'] = ['brand_name' => $brandSeries['brand'], 'exists' => $brand ? 1 : 0];
|
||||
if ($brand) {
|
||||
$item['brand']['id'] = $brand['id'];
|
||||
}
|
||||
$item['series'] = ['series_name' => $brandSeries['series'], 'exists' => $series ? 1 : 0];
|
||||
if ($series) {
|
||||
$item['series']['id'] = $series['id'];
|
||||
if (empty($item['brand']['id'])) {
|
||||
$item['brand']['id'] = $series['brand_id'];
|
||||
}
|
||||
}
|
||||
|
||||
//获取车型数据
|
||||
$item['model'] = [];
|
||||
if (count($brandSerieses)<2) {
|
||||
$item['model'] = $this->crawlSeriesModel($seriesId);
|
||||
}
|
||||
$result[] = $item;
|
||||
}
|
||||
|
||||
return $result;
|
||||
} catch (\Exception $e) {
|
||||
throw new \Exception($e->getMessage());
|
||||
|
||||
Reference in New Issue
Block a user