Menu

1 / 2

Web Scraping in 2025: Extract Any Website Data with Python

DEV Community·Brad·6 months ago
#mKrJZHMq
Reading 0:00
15s threshold

Web scraping lets you automatically collect data from any website. Here's how to do it with Python.

Basic Scraping with BeautifulSoup

import requests from bs4 import BeautifulSoup

def scrape_prices ( url ): headers = { ' User-Agent ' : ' Mozilla/5.0 ' } soup = BeautifulSoup ( requests . get ( url , headers = headers ). content , ' html.parser ' ) return [ item . text for item in soup . find_all ( ' span ' , class_ = ' price ' )]

prices = scrape_prices ( ' https://example-shop.com ' ) print ( f ' Found { len ( prices ) } prices ' )

Enter fullscreen mode

Exit fullscreen mode

For JavaScript-Heavy Sites

from playwright.sync_api import sync_playwright

with sync_playwright () as p : browser = p . chromium . launch () page = browser . new_page () page . goto ( ' https://dynamic-site.com ' ) page . wait_for_selector ( ' .data-table ' ) data = page . evaluate ( ' () => document.querySelector( " .data-table " ).innerText ' ) browser .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.