-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquotestoscrap.py
More file actions
31 lines (22 loc) · 841 Bytes
/
quotestoscrap.py
File metadata and controls
31 lines (22 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
""" A small python script to scrap all the quotes from http://quotes.toscrape.com and print them all"""
import requests
from bs4 import BeautifulSoup
def QuotesToScrap(pages):
""" Function to print quotes of every single page"""
for item in pages:
response = requests.get(item)
soup = BeautifulSoup(response.content, "lxml")
quotes = soup.find_all('div', {'class': 'quote'})
for q in quotes:
quote = q.find('span', {'class': 'text'}).text
author = q.find('small', {'class': 'author'}).text
print(quote + '\t' + 'by ' + author)
def main():
pages = []
for i in range(1, 11):
url = "http://quotes.toscrape.com/"
url = url + "page/{}/".format(i)
pages.append(url)
QuotesToScrap(pages)
if __name__ == '__main__':
main()