gepa
gepa

Reputation: 11

Web scraping using javascript

I want to make a site (with HTML, CSS and Javascript) which will scrape data from other sites. I want to use javascript in order to accomplish that. Which is the best way to do it? I would like to avoid using Node.js or some other framework.

Upvotes: 1

Views: 317

Answers (1)

Konrad
Konrad

Reputation: 24661

If you are getting cors error just use cors anywhere.

For dom parsing use DomParser

Example:

fetch(`https://cors-anywhere.herokuapp.com/${url}`)
.then(response => response.text())
.then(html => {
  const parser = new DOMParser()
  const dom = parser.parseFromString(htmlContent, 'text/html')
  // now you can select elements like for normal node
  dom.querySelector('div')
})

Do you have any other problems?

Upvotes: 3

Related Questions