-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQuote.py
More file actions
executable file
·31 lines (21 loc) · 904 Bytes
/
Quote.py
File metadata and controls
executable file
·31 lines (21 loc) · 904 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
from bs4 import BeautifulSoup
import urllib2
import random
def get_quote():
url = "https://www.goodreads.com/quotes"
quote_file = urllib2.urlopen(url)
quote_html = quote_file.read()
quote_file.close()
soup = BeautifulSoup(quote_html, "html.parser")
dic = {}
for quote_data in soup.find_all("div", attrs={"id" : "quoteoftheday"}):
for quote_text in quote_data.find_all("div", attrs={"class":"stacked mediumText"}):
for i in quote_text.find_all("i"):
dic["Quote"] = i.text
for quote_data in soup.find_all("div", attrs={"id" : "quoteoftheday"}):
for quote_author in quote_data.find_all("div", attrs={"class":"textRight"}):
for st in quote_author.find_all("strong", attrs={"class":"mediumText"}):
for a in st.find_all("a"):
dic["Authore"] = a.text
print dic
get_quote()