Created
November 4, 2020 11:39
-
-
Save Abhayparashar31/483cf0f9d0aa4f24d0a246d1db57d84b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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