Python How to click Divs using Selenium

Asked

Viewed 90 times

1

I’m trying to take jobs in google jobs and extract data to guadar in database or json.

Websites: GOOGLE JOBS SCREEN Notice how I have on the left a list with several jobs and when I click on some it displays on the screen next to more detailed information, as I do for each job on the left list to be clicked and then extract the text from the job title, as there in the image where it is written IT stage on the display side

My code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

url1 = 'https://www.google.com/search?client=firefox-b-d&ei=Ja39X_nUIKif5OUPp6eUkAE&q=vagas+estagio+ti&oq=vagas+estagio+ti&gs_lcp=CgZwc3ktYWIQAzIICAAQsQMQgwEyAggAMgIIADICCAAyAggAMgIIADICCAAyAggAMgIIADICCAA6BAgAEEc6CggAELEDEIMBEEM6BAgAEEM6DggAELEDEIMBEMcBEK8BOgsIABCxAxDHARCjAjoFCAAQsQM6BQguELEDOggIABDHARCvAVDeMFipTmClUGgCcAN4AIABnQKIAbUckgEGMC4xLjE1mAEAoAEBqgEHZ3dzLXdpesgBCMABAQ&sclient=psy-ab&uact=5&ibp=htl;jobs&sa=X&ved=2ahUKEwjZlb7fyJbuAhXWGbkGHdiZAEUQutcGKAB6BAgDEAQ#htivrt=jobs&fpstate=tldetail&htilrad=-1.0&htidocid=jN52cIGLUm9ZT0BQAAAAAA%3D%3D'

# Definindo Drive
driver = webdriver.Chrome(executable_path=r'./chromedriver')
driver.get(url1) # Entrando no url1

# Click

time.sleep(10)
driver.quit() # Fechando o driver

How can I do?

1 answer

0

An element can be clicked on Selenium through the function click():

elemento = driver.find_element_by_class_name('foo')
elemento.click()
  • But it has several elements with the same class, as I click on them°

  • In that case you can use find_elements_by_class_name, to return a list. See more about here: https://selenium-python.readthedocs.io/locating-elements.html

  • So my problem was that returns a kkkk list, thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.