-
Notifications
You must be signed in to change notification settings - Fork 2
/
manga_parser.js
217 lines (196 loc) · 8.2 KB
/
manga_parser.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import axios from 'axios';
import cheerio from 'cheerio';
const base_url = `https://chapmanganelo.com/`;
const recent_release_url = `https://m.manganelo.com/genre-all-update-latest`;
const latest_nextpage = `https://m.manganelo.com/genre-all/`;
const top_url = `https://m.manganelo.com/genre-all/`;
const top_type = `?type=topview`;
const new_manga_url = `https://m.manganelo.com/genre-all/`;
const new_manga_type = `?type=newest`;
const search_url = `https://m.manganelo.com/search/story/`;
const top_completed_manga = `https://m.manganelo.com/advanced_search?s=all&sts=completed&orby=topview&page=`;
export const scrapeLatestManga = async ({ list = [], page = 1 }) => {
try {
if (page === 1) {
const mainPage = await axios.get(recent_release_url);
const $ = cheerio.load(mainPage.data);
$('div.content-genres-item').each((i, el) => {
list.push({
mangaId: $(el).find('.genres-item-img').attr('href'),
mangaTitle: $(el).find('div.genres-item-info > h3 > a').text(),
chapterNum: $(el).find('.genres-item-chap').text(),
views: $(el).find('.genres-item-view').text(),
mangaImg: $(el).find('a > img').attr('src'),
});
});
} else {
const mainPage = await axios.get(`${latest_nextpage}${page}`);
const $ = cheerio.load(mainPage.data);
$('div.content-genres-item').each((i, el) => {
list.push({
mangaId: $(el).find('.genres-item-img').attr('href'),
mangaTitle: $(el).find('div.genres-item-info > h3 > a').text(),
chapterNum: $(el).find('.genres-item-chap').text(),
views: $(el).find('.genres-item-view').text(),
mangaImg: $(el).find('a > img').attr('src'),
description: $(el).find('.genres-item-description').text(),
});
});
}
return list;
} catch (err) {
throw err;
}
};
export const scrapeTopManga = async ({ list = [], page = 1 }) => {
try {
const mainPage = await axios.get(`${top_url}${page}${top_type}`);
const $ = cheerio.load(mainPage.data);
$('div.content-genres-item').each((i, el) => {
list.push({
mangaId: $(el).find('div.genres-item-info > a').attr('href'),
mangaTitle: $(el).find('div.genres-item-info > h3 > a').text(),
chapterNum: $(el).find('.genres-item-chap').text(),
views: $(el).find('.genres-item-view').text(),
mangaImg: $(el).find('a > img').attr('src'),
description: $(el).find('.genres-item-description').text(),
});
});
return list;
} catch (err) {
throw err;
}
};
export const scrapeNewManga = async ({ list = [], page = 1 }) => {
try {
const mainPage = await axios.get(`${new_manga_url}${page}${new_manga_type}`);
const $ = cheerio.load(mainPage.data);
$('div.content-genres-item').each((i, el) => {
list.push({
mangaId: $(el).find('div.genres-item-info > a').attr('href'),
mangaTitle: $(el).find('div.genres-item-info > h3 > a').text(),
chapterNum: $(el).find('.genres-item-chap').text(),
views: $(el).find('.genres-item-view').text(),
mangaImg: $(el).find('a > img').attr('src'),
description: $(el).find('.genres-item-description').text(),
});
});
return list;
} catch (err) {
throw err;
}
};
export const scrapeSearch = async ({ list = [], keyw, page = 1 }) => {
try {
const searchPage = await axios.get(
`${search_url}${keyw}?page=${page}`
);
const $ = cheerio.load(searchPage.data);
$('div.search-story-item').each((i, el) => {
list.push({
mangaId: $(el).find('.item-img').attr('href'),
mangaTitle: $(el).find('div.item-right > h3 > a').text(),
author: $(el).find('.item-author').eq(0).text(),
views: $(el).find('div.item-right > span').eq(2).text().replace('View : ', ''),
mangaImg: $(el).find('.img-loading').attr('src'),
last_update: $(el).find('div.item-right > span').eq(1).text().replace('Updated : ', ''),
});
});
return list;
} catch (err) {
console.log(err);
return { error: err };
}
};
export const scrapeTopCompletedManga = async ({ list = [], page = 1 }) => {
try {
const mainPage = await axios.get(`${top_completed_manga}${page}`);
const $ = cheerio.load(mainPage.data);
$('div.content-genres-item').each((i, el) => {
list.push({
mangaId: $(el).find('div.genres-item-info > a').attr('href'),
mangaTitle: $(el).find('div.genres-item-info > h3 > a').text(),
chapterNum: $(el).find('.genres-item-chap').text(),
views: $(el).find('.genres-item-view').text(),
mangaImg: $(el).find('a > img').attr('src'),
description: $(el).find('.genres-item-description').text(),
});
});
return list;
} catch (err) {
throw err;
}
};
export const scrapeMangaDetails = async ({ id }) => {
try {
let genres = [];
let chList = [];
let authors = [];
const animePageTest = await axios.get(`${base_url}${id}`);
const $ = cheerio.load(animePageTest.data);
const mangaTitle = $('div.story-info-right > h1').text();
const mangaImage = $('div.story-info-left > span > img').attr('src');
/*const author = $('table.variations-tableInfo > tbody > tr:nth-child(2) > td > a')
.text();*/
$('table.variations-tableInfo > tbody > tr:nth-child(2) > td > a.a-h').each((i, el) => {
authors.push({
authorName: $(el).text(),
});
});
const desc = $('div.panel-story-info-description')
.text()
.replace('Description :', '');
const updatedOn = $('div.story-info-right-extent > p:nth-child(1) > span')
.text()
.replace('Updated :', '');
const status = $('table.variations-tableInfo > tbody > tr:nth-child(3) > td')
.text()
.replace('Status :', '');
const alternativeTitle = $('table.variations-tableInfo > tbody > tr:nth-child(1) > td > h2')
.text()
.replace('Alternative :', '');
$('table.variations-tableInfo > tbody > tr:nth-child(4) > td:nth-child(2) > a.a-h').each((i, el) => {
genres.push({
genreId: $(el).attr('href'),
genreTitle: $(el).text(), // Splitting the genres here
});
});
$('#row-content-chapter > li').each((i, el) => {
chList.push({
chapterId: $(el).find('a').attr('href'),
chapterTitle: $(el).find('a').text(),
chapterViews: $(el).find(`span.chapter-view`).text(),
chapterUploadTime: $(el).find(`span.chapter-time`).text(),
});
});
return {
mangaTitle: mangaTitle.toString(),
mangaImg: mangaImage.toString(),
authors: authors,
updatedOn: updatedOn.toString(),
status: status.toString(),
genres: genres,
alternativeTitle: alternativeTitle,
synopsis: desc.toString(),
chapterList: chList,
};
} catch (err) {
console.log(err);
return { error: err };
}
};
export const scrapeGenreManga = async ({ list = [], page = 1 }) => {
try {
const mainPage = await axios.get(`${recent_release_url}`);
const $ = cheerio.load(mainPage.data);
$('div.panel-genres-list > a').each((i, el) => {
list.push({
genreId: $(el).attr('href'),
genreTitle: $(el).text(),
});
});
return list;
} catch (err) {
throw err;
}
};