-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathquotes.py
31 lines (17 loc) · 844 Bytes
/
quotes.py
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
import bs4, urllib.request as req, pandas as pd
url = "http://quotes.toscrape.com"
sauce = req.urlopen(url)
soup = bs4.BeautifulSoup(sauce, "html.parser")
sauce.close()
##author_quote = {a:b for a, b in zip([e.get_text() for e in soup.find_all("small", class_ = "author")], [d.get_text() for d in soup.find_all("span", class_ = "text")])}
quote = [i.get_text() for i in soup.find_all("span", class_ = "text")]
author = [i.get_text() for i in soup.find_all("small", class_ = "author")]
##author_quote = {i:j for i, j in zip(author, quote)}
author_quote_table = {}
author_quote_table["Author"] = author
author_quote_table["Quote"] = quote
df = pd.DataFrame(author_quote_table)
df.set_index("Author", inplace = True)
print(df)
##for key, value in author_quote.items():
## print(key + " : " + value)