mirror of
https://gitlab.com/moepoi/NekopoiScrapper.git
synced 2024-11-25 07:46:33 +01:00
Optimize getInfo
This commit is contained in:
parent
e4e8524b9c
commit
b7770e4483
1 changed files with 23 additions and 24 deletions
|
@ -7,29 +7,28 @@
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
const cheerio = require('cheerio');
|
const cheerio = require('cheerio');
|
||||||
|
|
||||||
let links = [];
|
const getInfo = url => {
|
||||||
|
|
||||||
const getInfo = (url) => {
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
axios.get(url).then(function(req) {
|
axios.get(url)
|
||||||
|
.then(req => {
|
||||||
|
try {
|
||||||
|
const links = [];
|
||||||
let soup = cheerio.load(req.data);
|
let soup = cheerio.load(req.data);
|
||||||
var title = soup("title").text();
|
let title = soup("title").text();
|
||||||
soup('div.liner').each(function(i, e) {
|
soup('div.liner').each(function(i, e) {
|
||||||
soup(e).find('div.listlink').each(function(j, s) {
|
soup(e).find('div.listlink').each(function(j, s) {
|
||||||
links.push(soup(s).find('a').attr('href'))
|
links.push(soup(s).find('a').attr('href'))
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
var data = {
|
const data = {
|
||||||
"title": title,
|
"title": title,
|
||||||
"links": links
|
"links": links
|
||||||
};
|
};
|
||||||
if (data == null) {
|
resolve(data)
|
||||||
reject("No result :(");
|
} catch (err) {
|
||||||
} else {
|
reject('Error : ' + err)
|
||||||
var result = JSON.stringify(data, null, 2);
|
|
||||||
resolve(result);
|
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue