from bs4 import BeautifulSoup import requests url = 'https://www.example.com' response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') # Extract all the links in the webpage for link in soup.find_all('a'): print(link.get('href'))
from bs4 import BeautifulSoup import requests url = 'https://www.example.com' response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') # Extract the text content of the paragraph tag paragraph = soup.find('p') print(paragraph.text)In both examples, we are importing the BeautifulSoup package from the bs4 library. We are then making a request to a webpage using the requests library and passing the response to BeautifulSoup. We use the find and find_all methods of BeautifulSoup to extract relevant tags and their contents from the webpage.