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

View file

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