Add AutoTrader (#999)
This commit is contained in:
parent
280a90b5c0
commit
9cb0105222
|
|
@ -2104,3 +2104,12 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运
|
|||
|
||||
<route name="分类筛选" author="MegrezZhu" example="/nhentai/language/chinese" path="/nhentai/:key/:keyword" :paramsDesc="['筛选条件,可选: parody, character, tag, artist, group, language, category','筛选值']" />
|
||||
<route name="高级搜索" author="MegrezZhu" example="/nhentai/search/language%3Ajapanese+-scat+-yaoi+-guro+-"e;mosaic+censorship"e;" path="/nhentai/search/:keyword" :paramsDesc="['用于搜索的关键词。可在原网站搜索后复制 q= 后面的内容,也可直接输入,但空格等特殊符号是否会转换取决于浏览器和阅读器的实现。用法详见[官网](https://nhentai.net/info/)']" />
|
||||
|
||||
### AutoTrader
|
||||
|
||||
<route name="搜索结果" author="HenryQW" example="/autotrader/radius=50&postcode=sw1a1aa&onesearchad=Used&onesearchad=Nearly%20New&onesearchad=New&price-to=9000&year-from=2012&body-type=Hatchback&transmission=Automatic&exclude-writeoff-categories=on" path="/autotrader/:query" :paramsDesc="['查询语句']">
|
||||
|
||||
1. 在 AutoTrader 选择筛选条件进行搜索
|
||||
1. 复制查询结果 URL 中`?`后的部分,例如 `https://www.autotrader.co.uk/car-search?radius=50&postcode=sw1a1aa&onesearchad=Used&onesearchad=Nearly%20New&onesearchad=New&price-to=9000&year-from=2012&body-type=Hatchback&transmission=Automatic&exclude-writeoff-categories=on` 则为 `radius=50&postcode=sw1a1aa&onesearchad=Used&onesearchad=Nearly%20New&onesearchad=New&price-to=9000&year-from=2012&body-type=Hatchback&transmission=Automatic&exclude-writeoff-categories=on`
|
||||
|
||||
</route>
|
||||
|
|
|
|||
|
|
@ -375,3 +375,12 @@ Provides a better reading experience (full text articles) over the official one.
|
|||
### 99% Invisible
|
||||
|
||||
<routeEn name="Transcript" author="Ji4n1ng" example="/99percentinvisible/transcript" path="/99percentinvisible/transcript"/>
|
||||
|
||||
### AutoTrader
|
||||
|
||||
<routeEn name="Search" author="HenryQW" example="/autotrader/radius=50&postcode=sw1a1aa&onesearchad=Used&onesearchad=Nearly%20New&onesearchad=New&price-to=9000&year-from=2012&body-type=Hatchback&transmission=Automatic&exclude-writeoff-categories=on" path="/autotrader/:query" :paramsDesc="['the search query']">
|
||||
|
||||
1. Conduct a search with desired filters on AutoTrader
|
||||
1. Copy everything in the URL after `?`, for example: `https://www.autotrader.co.uk/car-search?radius=50&postcode=sw1a1aa&onesearchad=Used&onesearchad=Nearly%20New&onesearchad=New&price-to=9000&year-from=2012&body-type=Hatchback&transmission=Automatic&exclude-writeoff-categories=on` will produce `radius=50&postcode=sw1a1aa&onesearchad=Used&onesearchad=Nearly%20New&onesearchad=New&price-to=9000&year-from=2012&body-type=Hatchback&transmission=Automatic&exclude-writeoff-categories=on`
|
||||
|
||||
</routeEn>
|
||||
|
|
|
|||
|
|
@ -715,4 +715,7 @@ router.get('/oilprice/:area', require('./routes/oilprice'));
|
|||
router.get('/nhentai/search/:keyword', require('./routes/nhentai/search'));
|
||||
router.get('/nhentai/:key/:keyword', require('./routes/nhentai/other'));
|
||||
|
||||
// Auto Trader
|
||||
router.get('/autotrader/:query', require('./routes/autotrader'));
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,75 @@
|
|||
const axios = require('../../utils/axios');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const link = `https://www.autotrader.co.uk/results-car-search?${ctx.params.query}`;
|
||||
const response = await axios.get(link);
|
||||
|
||||
const $ = cheerio.load(response.data.html);
|
||||
|
||||
const idList = $('li.search-page__result')
|
||||
.slice(0, 10)
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
idList.map(async (item) => {
|
||||
const link = `https://www.autotrader.co.uk/classified/advert/${item.attribs.id}`;
|
||||
|
||||
const cache = await ctx.cache.get(link);
|
||||
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
|
||||
const response = await axios.get(link);
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
let keyFacts = '<table><tr>';
|
||||
$('.keyFacts__list .keyFacts__label').each((i, e) => {
|
||||
keyFacts += `<td>${$(e).text()}</td>`;
|
||||
if ((i + 1) % 4 === 0) {
|
||||
keyFacts += '</tr><tr>';
|
||||
}
|
||||
});
|
||||
keyFacts += '</tr><tr>';
|
||||
|
||||
$('.fpaSpecifications__economy .fpaSpecifications__listItem').each((i, e) => {
|
||||
keyFacts += `<td>${$(e)
|
||||
.find('.fpaSpecifications__term')
|
||||
.text()}: ${$(e)
|
||||
.find('.fpaSpecifications__description')
|
||||
.text()}</td>`;
|
||||
if ((i + 1) % 4 === 0) {
|
||||
keyFacts += '</tr><tr>';
|
||||
}
|
||||
});
|
||||
|
||||
keyFacts += '</tr></table><br/>';
|
||||
|
||||
let images = '';
|
||||
|
||||
$('.fpa-image-overlay img').each((i, e) => {
|
||||
images += `<img src='${$(e).attr('data-src')}'/><br/>`;
|
||||
});
|
||||
|
||||
const description = keyFacts + images + $('meta[name="og:description"]').attr('content');
|
||||
|
||||
const title = `「${$('.fpaGallery__priceLabel').text()}」${$('meta[name="og:title"]').attr('content')}`;
|
||||
|
||||
const single = {
|
||||
title,
|
||||
description,
|
||||
pubDate: new Date().toISOString(),
|
||||
link,
|
||||
};
|
||||
ctx.cache.set(link, JSON.stringify(single), 2 * 60 * 60);
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: 'Auto Trader',
|
||||
link,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue