from kivy.app import App
from kivy.lang import Builder
from kivy.uix.scrollview import ScrollView
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
class MyButton(Button):
color=(0, 0, 0, 1)
valign='bottom'
padding_y=10
background_color=(.93, .91, .67, 1)
background_normal=''
class Box(BoxLayout):
orientation = "vertical"
padding = [5]
spacing = 10
def on_kv_post(self, widget):
self.add_widget(MyButton(text='И. С. Тургенев. «Отцы и дети»', on_press=self.btn_press))
def btn_press(self,instance):
self.clear_widgets()
sc = ScrollView(size_hint=(1, None))
x = 1
data = ''
while True:
if x == 1:
url = "http://loveread.ec/read_book.php?id=12021&p=1"
elif x < 57:
url = "http://loveread.ec/read_book.php?id=12021&p=" + f'{x}'
else:
break
request = requests.get(url)
soup = BeautifulSoup(request.text, "html.parser")
teme = soup.find_all("p", class_="MsoNormal")
for temes in teme:
data += temes.text
x = x + 1
sc.add_widget(Label(text=f'{data}'))
self.add_widget(sc)
class MyApp(App):
def build(self):
return Box()