Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. def poem_find_dop(message, name, n):
  2. try:
  3. r = requests.get(f'https://www.google.ru/search?newwindow=1&source=hp&ei={ei}&btnG=Поиск&q={name}+site%3Astihi.ru')
  4. r.encoding = 'cp1251'
  5. re = r.text
  6. soup = BeautifulSoup(re, 'html.parser')
  7. poem_url = str(soup.find_all('a')[27+n])
  8. r1 = poem_url.find('q=')
  9. r2 = poem_url.find('&')
  10. poem = poem_url[r1+2:r2]
  11. poem = requests.get(poem).text
  12. soup_1 = BeautifulSoup(poem, 'html.parser')
  13. text2 = soup_1.find_all('div')[6]
  14. poem = text2.text.replace(u'\xa0', u' ')
  15. bot.send_message(message.chat.id, poem)
  16. except:
  17. poem_find_dop(message, name, n+1)
  18. return poem
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement