cartoon-catch
Advanced tools
Comparing version 2.1.4 to 2.1.5
@@ -22,8 +22,7 @@ "use strict"; | ||
const grap = (pageUrl, options, transform) => __awaiter(void 0, void 0, void 0, function* () { | ||
const { target, headers = {}, slice = [], urlReplace, titleReplace, host = helper_1.getHost(pageUrl) } = options; | ||
const { target, slice = [], urlReplace = [], titleReplace = [], host = helper_1.getHost(pageUrl) } = options; | ||
// const urlReplace: [any?, any?] = options.urlReplace || []; | ||
if (!target) | ||
throw new Error('请输入target'); | ||
let html = yield helper_1.getHtml(pageUrl, { | ||
headers | ||
}) | ||
let html = yield helper_1.getHtml(pageUrl, options) | ||
.catch(e => { | ||
@@ -37,12 +36,11 @@ error(`请求超时 ${pageUrl} ${e}`); | ||
const urls = $(target).toArray().slice(...slice).map(item => { | ||
let url = $(item).attr('href'); | ||
let url = $(item).attr('href').replace(...urlReplace); | ||
if (!/^http(s)?:\/\//.test(url)) { | ||
url = `${host}${url}`; | ||
} | ||
let title = $(item).text().trim(); | ||
urlReplace && (url = url.replace(urlReplace[0], urlReplace[1])); | ||
titleReplace && (title = title.replace(titleReplace[0], titleReplace[1])); | ||
let title = $(item).text().trim().replace(...titleReplace); | ||
return [url, title]; | ||
}); | ||
log(urls); | ||
// downloadImages | ||
return downloadImages(urls, options, transform); | ||
@@ -49,0 +47,0 @@ }); |
{ | ||
"name": "cartoon-catch", | ||
"version": "2.1.4", | ||
"version": "2.1.5", | ||
"description": "cartoon-catch", | ||
@@ -5,0 +5,0 @@ "main": "dist/main.js", |
@@ -20,4 +20,4 @@ import { OptionsInterface as downloadOptionsInterface } from './download.interface'; | ||
host: string | ||
urlReplace: Array<any> | ||
titleReplace: Array<any> | ||
urlReplace: [string?, string?] | ||
titleReplace: [string?, string?] | ||
beforeFunction: Function | ||
@@ -24,0 +24,0 @@ imageHost: string |
@@ -14,12 +14,10 @@ | ||
target, | ||
headers = {}, | ||
slice = [], | ||
urlReplace, | ||
titleReplace, | ||
urlReplace = [], | ||
titleReplace = [], | ||
host = getHost(pageUrl) | ||
} = options; | ||
// const urlReplace: [any?, any?] = options.urlReplace || []; | ||
if(!target) throw new Error('请输入target'); | ||
let html = await getHtml(pageUrl, { | ||
headers | ||
}) | ||
let html = await getHtml(pageUrl, options) | ||
.catch(e => { | ||
@@ -32,12 +30,11 @@ error(`请求超时 ${pageUrl} ${e}`) | ||
const urls = $(target).toArray().slice(...slice).map(item => { | ||
let url = $(item).attr('href'); | ||
let url = $(item).attr('href').replace(...urlReplace); | ||
if(!/^http(s)?:\/\//.test(url)){ | ||
url = `${host}${url}`; | ||
} | ||
let title = $(item).text().trim(); | ||
urlReplace && (url = url.replace(urlReplace[0], urlReplace[1])) | ||
titleReplace && (title = title.replace(titleReplace[0], titleReplace[1])) | ||
let title = $(item).text().trim().replace(...titleReplace); | ||
return [url, title]; | ||
}); | ||
log(urls) | ||
// downloadImages | ||
return downloadImages(urls, options, transform) | ||
@@ -44,0 +41,0 @@ } |
24422
559