hop
This commit is contained in:
parent
4faa6ef364
commit
7c5e018a3c
2
index.ts
2
index.ts
@ -71,7 +71,7 @@ async function init() {
|
|||||||
console.log(
|
console.log(
|
||||||
'⌛ trouver les évènements qui ne font pas partie de la BDD mobilizon postgresql',
|
'⌛ trouver les évènements qui ne font pas partie de la BDD mobilizon postgresql',
|
||||||
);
|
);
|
||||||
feed.items.forEach((eventFound) => {
|
feed.items.forEach((eventFound:any) => {
|
||||||
utilsTools.agendadulibre.doesEventExists(eventFound);
|
utilsTools.agendadulibre.doesEventExists(eventFound);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,10 @@
|
|||||||
const puppeteer = require('puppeteer');
|
const puppeteer = require('puppeteer');
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
import parserConfig from "../config";
|
||||||
|
|
||||||
// configure database
|
// configure database
|
||||||
|
|
||||||
// get data from webpage
|
// get data from webpage
|
||||||
function saveScrappeddata(data: any) {
|
|
||||||
let fileName = 'ccpl_scrapped.json';
|
|
||||||
|
|
||||||
fs.writeFile(
|
|
||||||
`./sources_examples/${fileName}`,
|
|
||||||
JSON.stringify(data, null, 4),
|
|
||||||
"utf8",
|
|
||||||
(err: any) => {
|
|
||||||
if (err) {
|
|
||||||
console.log(`Error writing file: ${err}`);
|
|
||||||
} else {
|
|
||||||
console.log(`File ${fileName} is written successfully!`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let options: any = {};
|
let options: any = {};
|
||||||
let scrappedData: any = {
|
let scrappedData: any = {
|
||||||
@ -81,23 +66,41 @@ async function run() {
|
|||||||
|
|
||||||
|
|
||||||
let ii = 0;
|
let ii = 0;
|
||||||
|
|
||||||
|
|
||||||
dataRun.listOfElementsLinks.forEach((url: string) => {
|
dataRun.listOfElementsLinks.forEach((url: string) => {
|
||||||
// add delay
|
// add delay
|
||||||
console.log('url', url);
|
console.log('url', url);
|
||||||
// if(ii<3){
|
if (ii < 3) {
|
||||||
// getEventPageInfo(url)
|
let eventInfo = getEventPageInfo(url)
|
||||||
//
|
scrappedData.pages.push(eventInfo);
|
||||||
// }
|
}
|
||||||
ii++;
|
ii++;
|
||||||
})
|
})
|
||||||
|
|
||||||
// browser.close();
|
|
||||||
console.log('DONE');
|
console.log('DONE');
|
||||||
saveScrappeddata({scrappedData, ...dataRun});
|
let data = {scrappedData, ...dataRun};
|
||||||
|
let fileName = 'ccpl_scrapped.json';
|
||||||
|
|
||||||
|
fs.writeFile(
|
||||||
|
`./sources_examples/${fileName}`,
|
||||||
|
JSON.stringify(data, null, 4),
|
||||||
|
"utf8",
|
||||||
|
(err: any) => {
|
||||||
|
if (err) {
|
||||||
|
console.log(`Error writing file: ${err}`);
|
||||||
|
} else {
|
||||||
|
console.log(`File ${fileName} is written successfully!`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
browser.close();
|
||||||
return dataRun;
|
return dataRun;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getEventPageInfo(url: string) {
|
async function getEventPageInfo(url: string):Promise<any> {
|
||||||
const browser = await puppeteer.launch(options);
|
const browser = await puppeteer.launch(options);
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
await page.goto(url);
|
await page.goto(url);
|
||||||
|
Loading…
Reference in New Issue
Block a user