-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcrawl-iQIYI-movie-resources.js
49 lines (41 loc) · 1.16 KB
/
crawl-iQIYI-movie-resources.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const http = require('http');
const fs = require('fs');
const request = require('request-promise')
const jsdom = require('jsdom');
const {JSDOM} = jsdom;
const config = {
"pageMaxNum": "10",
"parseURL": "http://vip.jlsprh.com/index.php?url="
}
class reptilesController {
async index() {
const dHTML = await Promise.all(await this.fetchHandler())
this.ctx.body = await this.parseHTML(dHTML)
}
async fetch(url) {
return request(url, function (err, res, data) {
return Buffer.concat([new Buffer(data)]).toString();
})
}
async fetchHandler() {
let promiseList = [];
for (let i = 1; i <= config.pageMaxNum; i++) {
promiseList.push(this.fetch(reptilesController.getSourceURL(i)));
}
return promiseList;
}
static getSourceURL(index) {
return `http://list.iqiyi.com/www/1/-------------11-${index}-1-iqiyi--.html`
}
async parseHTML(html) {
const dom = new JSDOM(html);
let aList = dom.window.document.querySelectorAll('div.site-piclist_pic > a');
aList = Array.from(aList);
return aList.map((a) => {
return {
title: a.title,
url: `${config.parseURL}${a.href}`
}
});
}
}