Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def poem_find_dop(message, name, n):
- try:
- r = requests.get(f'https://www.google.ru/search?newwindow=1&source=hp&ei={ei}&btnG=Поиск&q={name}+site%3Astihi.ru')
- r.encoding = 'cp1251'
- re = r.text
- soup = BeautifulSoup(re, 'html.parser')
- poem_url = str(soup.find_all('a')[27+n])
- r1 = poem_url.find('q=')
- r2 = poem_url.find('&')
- poem = poem_url[r1+2:r2]
- poem = requests.get(poem).text
- soup_1 = BeautifulSoup(poem, 'html.parser')
- text2 = soup_1.find_all('div')[6]
- poem = text2.text.replace(u'\xa0', u' ')
- bot.send_message(message.chat.id, poem)
- except:
- poem_find_dop(message, name, n+1)
- return poem
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement