Web scraping in React Native
I was recently working on a React Native app where I had to scrape data from a site and use it in my app.
Initially, I used Node js and Express to make a REST API, then I used Cheerio to parse the HTML.
This setup became a problem as the number of people that used my app increased. The website would block requests from my server or redirect them to a CAPTCHA page.
The solution I came up with was to do the web scraping on the client-side.
How to Web Scrape in React Native
In this example, I will be scraping eBay for drones.
Step 1 - Install cheerio-without-node-native
npm i cheerio-without-node-nativeStep 2 - Get the HTML from the Website
import cio from 'cheerio-without-node-native'const URL = "https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2380057.m570.l1313&_nkw=drones&_sacat=0"async function getDroneData() {
const response = await fetch(Url); // fetch page
const data = await response.text(); // get response text
}
Step 3 - Extract the Needed Data from the HTML
If you need an in-depth explanation of the code above or have a question, let me know in the comments section.
