Write a python script that can scrape a web page.
- User
Write a python script that can scrape a web page.
Assistant
Here is a basic Python script that uses the BeautifulSoup library to scrape a web page:
import requests from bs4 import BeautifulSoup url = 'https://www.example.com' response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') # Find all paragraph tags paragraphs = soup.find_all('p') for paragraph in paragraphs: print(paragraph.text) # Find element with id="heading" heading = soup.find(id="heading") print(heading.text) # Find all links links = soup.find_all('a') for link in links: print(link.text)This script:
- Imports the requests and BeautifulSoup libraries
- Makes a GET request to the given URL
- Parses the response text with BeautifulSoup
- Finds all tags and prints their text
- Finds the element with id="heading" and prints its text
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.