File size: 1,674 Bytes
f791a0b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38d95ee
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import requests
import pandas as pd
from bs4 import BeautifulSoup
import re
     

URL = "https://www.goodreads.com/list/show/79160"
page = requests.get(URL)
     

soup = BeautifulSoup(page.content, "html.parser")
     
booktitle = []
for item in soup.find_all('span', itemprop="name", role="heading"):
  booktitle.append(item.get_text())


author = []
for item in soup.find_all('a', {'class' : 'authorName'}):
  author.append(item.get_text())


avg_rating = []
for item in soup.find_all('span', {'class' : 'minirating'}):
  avg_rating.append(item.get_text())


ratings = []
for i in range (len(avg_rating)):
  num = re.sub('\D', '', avg_rating[i])[:3]
  rating = num[0] + '.' + num[1:] 
  ratings.append(rating)


data = pd.DataFrame()

data['Book Title'] = booktitle
data['Author'] = author
data['Average Rating'] = ratings


#streamlit

import streamlit as st

st.title("Most Popular Mysteries on Goodreads")
st.caption("data collected by a web scraping script written in Python")

title = st.text_input('check if author is on the list:')

if title.isspace() == False and title != '':
    st.caption('Results:')
    for i in range(len(author)):
        if title in author[i].lower():          
            st.write(author[i],' ,', booktitle[i])
        if i == (len(author)-1):
            st.caption('_end of results_')


st.dataframe(data)







@st.cache
def convert_df(data):
    # IMPORTANT: Cache the conversion to prevent computation on every rerun
    return data.to_csv().encode('utf-8')

csv = convert_df(data)

st.download_button(
    label="Download data as CSV",
    data=csv,
    file_name='Most_Popular_Mysteries_on_Goodreads.csv',
    mime='text/csv',
)