Skip to content

Instantly share code, notes, and snippets.

View dragoscv's full-sized avatar

Dragos Catalin dragoscv

View GitHub Profile
@dragoscv
dragoscv / crawler-nxp.js
Created August 24, 2023 23:04
Crawler nxp node js puppeteer
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch(
// {
// headless: false,
// defaultViewport: null,
// args: ['--start-maximized']
// }
);
@dragoscv
dragoscv / crawler.js
Created August 24, 2023 21:23
Crawler JavaScript
fetch('https://www.libertatea.ro/')
.then(response => response.text())
.then(data => {
var parser = new DOMParser();
var doc = parser.parseFromString(data, 'text/html');
// console.log(doc);
var articles = [];
var articleElements = doc.querySelector('.opinions-and-news ul').querySelectorAll('li');
console.log(articleElements)
@dragoscv
dragoscv / crawler-minified.js
Created August 24, 2023 21:22
Crawler minified
fetch('https://www.libertatea.ro/').then(response=>response.text()).then(data=>{var parser=new DOMParser(),doc=parser.parseFromString(data,'text/html'),articles=[],articleElements=doc.querySelector('.opinions-and-news ul').querySelectorAll('li');for(var i=1;i<Math.min(articleElements.length,4);i++){var title=articleElements[i].querySelector('h3.article-title').textContent,link=articleElements[i].querySelector('a').getAttribute('href');articles.push({title:title,link:link})}console.log(JSON.stringify(articles,null,2))}).catch(error=>console.Error(error));