Answer the question
In order to leave comments, you need to log in
How to make a google image parser for a telegram bot?
Hello everyone. Can you tell me how to make a google image parser using selenium for a telegram bot? I tried this option, but it doesn't work.
import telebot
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox(executable_path=r'C:\FILES\geckodriver-v0.29.1-win64\geckodriver.exe')
Token = '...'
bot = telebot.TeleBot(Token)
@bot.message_handler(commands=['photo'])
def seeaarch(message):
msg = bot.send_message(message.chat.id, 'Что именно?')
bot.register_next_step_handler(msg, searchForPhoto)
def searchForPhoto(message):
bot.send_message(message.from_user.id, 'Так где оно тут у нас...')
photo_href = "https://www.google.com/search?q=" + message.text + "&tbm=isch&ved=2ahUKEwiBz5Svn5XxAhXkkcMKHa2uD5sQ2-cCegQIABAA&oq=" + message.text + "&gs_lcp=CgNpbWcQAzIECCMQJzIECCMQJzICCAAyAggAMgIIADICCAAyAggAMgIIADICCAAyAggAUPUMWPUMYNgPaABwAHgAgAFPiAFPkgEBMZgBAKABAaoBC2d3cy13aXotaW1nwAEB&sclient=img&ei=MU_GYMHyHuSjjgat3b7YCQ&bih=937&biw=1920"
driver.get(photo_href)
photos = driver.find_element_by_class_name("rg_i Q4LuWd")
for v in range(len(photos)):
bot.send_message(message.chat.id, photos[v].get_attribute('img'))
bot.polling(none_stop=True)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question