Skip to content

Instantly share code, notes, and snippets.

@Codehunter-py
Created July 28, 2022 11:40
Show Gist options
  • Save Codehunter-py/6e297749b63b6247c1cbd1cd59eba0fe to your computer and use it in GitHub Desktop.
Save Codehunter-py/6e297749b63b6247c1cbd1cd59eba0fe to your computer and use it in GitHub Desktop.
Creating a request and parsing a web page
import requests
from bs4 import BeautifulSoup
def scrape_page(url):
response = requests.get(url)
soup = BeautifulSoup(response.text,'lxml')
print(soup)
quotes = soup.find_all("span", class_="text")
authors = soup.find_all("small", class_="author")
tags = soup.find_all("div", class_="tags")
for i in range(0,len(quotes)):
print(quotes[i].text)
print(authors[i].text)
quoteTags = tags[i].find_all('a',class_='tag')
for quoteTag in quoteTags:
print(quoteTag.text)
scrape_page("https://quotes.toscrape.com/")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment