better-ani-scraped 1.2.2 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/scrapers/animesama.js +33 -68
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-ani-scraped",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"description": "Scrape anime data from different sources (only anime-sama.fr for the moment)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"ani-scraped": "^1.2.8",
|
|
21
21
|
"axios": "^1.8.4",
|
|
22
22
|
"cheerio": "^1.0.0",
|
|
23
|
-
"
|
|
23
|
+
"playwright": "^1.52.0"
|
|
24
24
|
},
|
|
25
25
|
"repository": {
|
|
26
26
|
"type": "git",
|
package/scrapers/animesama.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import * as cheerio from "cheerio";
|
|
3
3
|
import fs from "fs";
|
|
4
|
-
import puppeteer from'puppeteer';
|
|
5
4
|
|
|
6
5
|
const BASE_URL = "https://anime-sama.fr";
|
|
7
6
|
const CATALOGUE_URL = `${BASE_URL}/catalogue`;
|
|
@@ -124,77 +123,43 @@ export async function getSeasons(animeUrl, language = "vostfr") {
|
|
|
124
123
|
return seasons;
|
|
125
124
|
}
|
|
126
125
|
|
|
127
|
-
|
|
128
|
-
let browser;
|
|
129
|
-
try {
|
|
130
|
-
console.log("🔧 [1] Lancement de Puppeteer...");
|
|
131
|
-
browser = await puppeteer.launch({
|
|
132
|
-
headless: true,
|
|
133
|
-
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
|
134
|
-
});
|
|
126
|
+
import { chromium } from 'playwright';
|
|
135
127
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
req.continue();
|
|
154
|
-
}
|
|
155
|
-
});
|
|
128
|
+
export async function getEpisodeTitles(animeUrl) {
|
|
129
|
+
let browser;
|
|
130
|
+
try {
|
|
131
|
+
browser = await chromium.launch({ headless: true });
|
|
132
|
+
const context = await browser.newContext({
|
|
133
|
+
locale: 'fr-FR',
|
|
134
|
+
userAgent: 'Mozilla/5.0'
|
|
135
|
+
});
|
|
136
|
+
const page = await context.newPage();
|
|
137
|
+
await page.route('**/*', (route) => {
|
|
138
|
+
const blocked = ['image', 'stylesheet', 'font', 'media'];
|
|
139
|
+
if (blocked.includes(route.request().resourceType())) {
|
|
140
|
+
route.abort();
|
|
141
|
+
} else {
|
|
142
|
+
route.continue();
|
|
143
|
+
}
|
|
144
|
+
});
|
|
156
145
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const html = await page.content();
|
|
172
|
-
fs.writeFileSync(path.resolve(`page-${Date.now()}.html`), html);
|
|
173
|
-
|
|
174
|
-
console.log("🔍 [11] Vérification existence du select...");
|
|
175
|
-
const selectExists = await page.$('#selectEpisodes') !== null;
|
|
176
|
-
console.log("#selectEpisodes existe :", selectExists);
|
|
177
|
-
|
|
178
|
-
console.log("🧠 [12] Récupération des titres d'épisodes...");
|
|
179
|
-
const titres = await page.$$eval('#selectEpisodes option', options =>
|
|
180
|
-
options.map(o => o.textContent.trim())
|
|
181
|
-
);
|
|
182
|
-
|
|
183
|
-
console.log("📋 [13] Titres récupérés :", titres);
|
|
184
|
-
return titres;
|
|
185
|
-
|
|
186
|
-
} catch (error) {
|
|
187
|
-
console.error("❌ Erreur dans la récupération des titres :", error);
|
|
188
|
-
return [];
|
|
189
|
-
} finally {
|
|
190
|
-
if (browser) {
|
|
191
|
-
console.log("🧹 [14] Fermeture du navigateur...");
|
|
192
|
-
await browser.close();
|
|
193
|
-
}
|
|
194
|
-
console.log("✅ [15] Fin de la fonction getEpisodeTitles.");
|
|
195
|
-
}
|
|
146
|
+
await page.goto(animeUrl, { waitUntil: 'domcontentloaded', timeout: 20000 });
|
|
147
|
+
await page.waitForSelector('#selectEpisodes', { timeout: 10000 });
|
|
148
|
+
const titres = await page.$$eval('#selectEpisodes option', options =>
|
|
149
|
+
options.map(o => o.textContent.trim())
|
|
150
|
+
);
|
|
151
|
+
return titres;
|
|
152
|
+
} catch (error) {
|
|
153
|
+
console.error('❌ Erreur dans la récupération des titres :', error);
|
|
154
|
+
return [];
|
|
155
|
+
} finally {
|
|
156
|
+
if (browser) {
|
|
157
|
+
await browser.close();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
196
160
|
}
|
|
197
161
|
|
|
162
|
+
|
|
198
163
|
export async function getEmbed(animeUrl, hostPriority = ["vidmoly"]) {
|
|
199
164
|
const res = await axios.get(animeUrl, {
|
|
200
165
|
headers: getHeaders(animeUrl.split("/").slice(0, 5).join("/")),
|