Skip to content

Instantly share code, notes, and snippets.

@Abhayparashar31
Created November 4, 2020 11:39
Show Gist options
  • Save Abhayparashar31/483cf0f9d0aa4f24d0a246d1db57d84b to your computer and use it in GitHub Desktop.
Save Abhayparashar31/483cf0f9d0aa4f24d0a246d1db57d84b to your computer and use it in GitHub Desktop.
import requests
from bs4 import BeautifulSoup
import csv
######## SCRAPING QUOTES FROM ALL THE PAGES
page = 10 ## Number of Pages you want to scrape
for i in range(0,page):
res = requests.get(f"http://quotes.toscrape.com/page/{i}/")
soup = BeautifulSoup(res.text,"html.parser")
### Finding the Page Length
length = len(soup.select(".text"))
### Scraping All the Quotes with author name
for j in range(0,length):
quote = soup.select(".text")[j].get_text().strip()
quote = quote.replace("\u2032"," ")
author = soup.select('.author')[j].get_text().strip()
### Opening a CSV file
with open('quote.csv','a',newline='') as f:
### Defining a write
writer = csv.writer(f)
#### Using the writer append a row
writer.writerow([quote,author])
print("Done!") ###Sucess Message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment