去除多余文件
This commit is contained in:
@@ -1,90 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\logic\BrandLogic;
|
||||
use QL\QueryList;
|
||||
|
||||
class CrawlService
|
||||
{
|
||||
public function brandSeries($brand)
|
||||
{
|
||||
$url = "https://www.dongchedi.com/search?currTab=6&keyword=".$brand.'&from=search_tab_er&api_param={"en_qc":+0}';
|
||||
$ql = QueryList::get($url );
|
||||
$series = [];
|
||||
$ql->find('div.card-name')->texts()->map(function($item) use(&$series) {
|
||||
$series[] = $item;
|
||||
});
|
||||
return $series;
|
||||
}
|
||||
|
||||
public function seriesModel($series)
|
||||
{
|
||||
$href = $this->modelSearch($series);
|
||||
|
||||
//例如 $seriesUrl = "https://www.dongchedi.com/auto/series/4865?anchorId=carModels"
|
||||
if (empty($href)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$seriesUrl = (strpos($href, 'http') === 0) ? $href : ("https://www.dongchedi.com" . $href);
|
||||
$ql = QueryList::get($seriesUrl);
|
||||
|
||||
$nodes = $ql->find('div.tw-grid div.tw-relative div.tw-items-center>a');
|
||||
$texts = $nodes->texts()->all();
|
||||
$links = $nodes->attrs('href')->all();
|
||||
$nodes = $ql->find('div.tw-grid div.tw-text-color-gray-800');
|
||||
$price = $nodes->texts()->all();
|
||||
|
||||
$results = [];
|
||||
foreach ($texts as $index => $text) {
|
||||
$link = $links[$index] ?? '';
|
||||
if (!empty($link) && strpos($link, 'http') !== 0) {
|
||||
$link = 'https://www.dongchedi.com' . $link;
|
||||
}
|
||||
$results[] = [
|
||||
'title' => trim($text),
|
||||
'link' => $link,
|
||||
'msrp' => (int)(str_replace("万", "", $price[$index]) * 10000) ?? 0,
|
||||
];
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
// public function modelDesc(array $models)
|
||||
// {
|
||||
//
|
||||
// }
|
||||
|
||||
/**
|
||||
* 返回车系地址
|
||||
* @param $series
|
||||
* @return mixed|string
|
||||
*/
|
||||
public function modelSearch($series)
|
||||
{
|
||||
$url = "https://www.dongchedi.com/search?keyword=".$series;
|
||||
$ql = QueryList::get($url );
|
||||
$href = '';
|
||||
$ql->find('a.fold-btn')->attrs('href')
|
||||
->map(function ($item) use(&$href) {
|
||||
$href = $item;
|
||||
});
|
||||
return $href;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关键词搜索的更多页面,通过面包屑抓取品牌与系列
|
||||
* @param $series
|
||||
* @return mixed|string
|
||||
*/
|
||||
public function crawlBrandSeries($series)
|
||||
{
|
||||
$url = "https://www.dongchedi.com/auto/series/" . $series . "?anchorId=carModels";
|
||||
$ql = QueryList::get($url);
|
||||
$result = $ql->find('div.breadcrumb_wrap__2GLeU span')->texts()->all();
|
||||
|
||||
return ['brand' => $result[2], 'series' => $result[3]];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user