fix y_search

This commit is contained in:
Von Random 2023-11-10 01:02:27 +02:00
parent 75c8727097
commit c65787b6bd
2 changed files with 7 additions and 8 deletions

View file

@ -5,9 +5,9 @@ import random
import re
import typing
import requests
import bs4
import fake_headers
import requests
import pgbotlib.dbstuff
@ -69,14 +69,14 @@ class ApiWrapper:
'isize': 'medium'},
headers=self.headers.generate())
parser = bs4.BeautifulSoup(request.text, 'html.parser')
items_place = parser.find('div', {'class': 'serp-list'})
items = items_place.find_all('div', {'class': 'serp-item'})
items_tag = parser.find('div', {'role': 'main'})
items_full = json.loads(items_tag.find('div')['data-state'])
items = items_full['initialState']['serpList']['items']['entities']
images = []
for item in items:
data = json.loads(item.get('data-bem'))
images.append(data['serp-item']['img_href'])
for item in items.values():
images.append(item.get('origUrl'))
if not images:
return None
return self.FAILED
result = random.choice(images)
return f'[url]({result})'

View file

@ -3,7 +3,6 @@
import telethon
import telethon.utils
import pgbotlib.api
import pgbotlib.dbstuff
import pgbotlib.misc
import pgbotlib.response