Skip to content
Advertisements

Google Search With Python Selenium

from selenium import webdriver
import time

# open firefox
browser = webdriver.Firefox()          
browser.get("https://www.google.com.tr/")     
time.sleep(1)                       

# search input field
search = browser.find_element_by_xpath("//*[@id='tsf']/div[2]/div/div[1]/div/div[1]/input") 
search.send_keys("javascript")
time.sleep(1)                       

# search button
search_button = browser.find_element_by_xpath("//*[@id='tsf']/div[2]/div/div[2]/div[2]/div[2]/center/input[1]")
search_button.submit()
time.sleep(3)                       

# get value search title
elements = browser.find_elements_by_css_selector(".LC20lb")
for element in elements:
    print("________________________________________")
    print(element.text)
time.sleep(3)

# next page
next_page = browser.find_element_by_xpath("//*[@id='nav']/tbody/tr/td[3]/a")
next_page.click()
time.sleep(1)

# get value search title
elements = browser.find_elements_by_css_selector(".LC20lb")
for element in elements:
    print("________________________________________")
    print(element.text)
time.sleep(3)

# next page
next_page = browser.find_element_by_xpath("//*[@id='nav']/tbody/tr/td[4]/a")
next_page.click()
time.sleep(1)

# get value search title
elements = browser.find_elements_by_css_selector(".LC20lb")
for element in elements:
    print("________________________________________")
    print(element.text)
time.sleep(3)

# close firefox
browser.close()
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: