Skip to content

Instantly share code, notes, and snippets.

@sourleangchhean168
Created November 8, 2024 02:59
Show Gist options
  • Save sourleangchhean168/0b1c1703f395088b022db3baff899c78 to your computer and use it in GitHub Desktop.
Save sourleangchhean168/0b1c1703f395088b022db3baff899c78 to your computer and use it in GitHub Desktop.
Scrape
import requests
from bs4 import BeautifulSoup
# URL of the website you want to scrape
url = 'https://example.com'
# Send an HTTP request to the URL
response = requests.get(url)
# Check if the request was successful
if response.status_code == 200:
# Parse the page content
soup = BeautifulSoup(response.text, 'html.parser')
# Extract specific content, for example, all paragraph elements
paragraphs = soup.find_all('p')
# Loop through the paragraphs and print the text content
for paragraph in paragraphs:
print(paragraph.get_text())
else:
print(f'Failed to retrieve the web page. Status code: {response.status_code}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment