Which is better for web scraping Python or JavaScript?

Short answer: Python!

Long answer: it depends.

If you're scraping simple websites with a simple HTTP request. Python is your best bet.

Libraries such as requests or HTTPX makes it very easy to scrape websites that don't require JavaScript to work correctly. Python offers a lot of simple-to-use HTTP clients.

And once you get the response, it's also very easy to parse the HTML with BeautifulSoup for example. 

Here is a very quick example of how simple it is to scrape a website and extract its title:

import requests
from bs4 import BeautifulSoup

response = requests.get("https://news.ycombinator.com/")
soup = BeautifulSoup(response.content, 'html.parser')

# The title tag of the page
> <title>Hacker News</title>

# The title of the page as string
> Hacker News

You can use JavaScript to do web scraping if you want to scrape websites that require a lot of JavaScript to work correctly.

To scrape such websites you will need to use what is called a "headless browser", meaning that a real web browser will fetch and render the website for you. The easiest and most popular library used to do this is Puppeteer, a JavaScript library. 

Go back to web scraping questions