Skip to content

Instantly share code, notes, and snippets.

@dragoscv
Created August 24, 2023 21:22
Show Gist options
  • Save dragoscv/a4399a98ca749e7056e8910d1c539d48 to your computer and use it in GitHub Desktop.
Save dragoscv/a4399a98ca749e7056e8910d1c539d48 to your computer and use it in GitHub Desktop.
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));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment