What are some common user-agent strings to use when scraping with JavaScript?

User-agent strings are important when you are performing web scraping because they tell the web server about the type of device and browser you are using to request the content. Some websites use the user-agent string to serve different content or to block requests from bots or scrapers. By using a common user-agent string that imitates a popular browser, your scraper can blend in with regular web traffic.

Here are some common user-agent strings that you can use when scraping with JavaScript (or any other language):

Desktop Browsers:

  • Google Chrome on Windows 10: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36

  • Mozilla Firefox on Windows 10: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0

  • Microsoft Edge on Windows 10: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36 Edg/88.0.705.50

  • Apple Safari on macOS: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Safari/605.1.15

Mobile Browsers:

  • Google Chrome on Android: Mozilla/5.0 (Linux; Android 11; Pixel 5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.152 Mobile Safari/537.36

  • Safari on iPhone (iOS): Mozilla/5.0 (iPhone; CPU iPhone OS 14_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Mobile/15E148 Safari/604.1

When using JavaScript for web scraping, you might be using tools like axios, request, or node-fetch to make HTTP requests, and you can set the user-agent string in the headers of your request. Here is an example using axios in Node.js:

const axios = require('axios');

const url = 'https://example.com';

axios.get(url, {
  headers: {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36'
  }
})
.then(response => {
  console.log(response.data);
})
.catch(error => {
  console.error('Error fetching the page:', error);
});

Remember that web scraping should always be performed responsibly and ethically. Always check the website's robots.txt file and terms of service to understand the scraping policies, and avoid overwhelming the website's servers with too many rapid requests. Additionally, be aware that using a user-agent to mimic a browser does not give you permission to scrape a website if it is against the website's policies.

Related Questions

Get Started Now

WebScraping.AI provides rotating proxies, Chromium rendering and built-in HTML parser for web scraping
Icon