-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb.py
More file actions
29 lines (23 loc) · 849 Bytes
/
web.py
File metadata and controls
29 lines (23 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import requests
from bs4 import BeautifulSoup
def scrape_website(url):
# Send an HTTP GET request to the URL
response = requests.get(url)
# Check if the request was successful (status code 200)
if response.status_code == 200:
# Parse the HTML content of the page
soup = BeautifulSoup(response.content, 'html.parser')
# Extract data from the parsed HTML
# Example: Extract all the text from <h1> tags
headings = soup.find_all('h1')
for heading in headings:
print(heading.text)
else:
print("Failed to retrieve data from the website.")
def main():
# URL of the website to scrape
url = 'https://example.com'
# Call the scrape_website function with the URL
scrape_website(url)
if __name__ == "__main__":
main()