Skip to content

Commit c382c74

Browse files
authored
Merge pull request #17 from anishk23733/master
Web Interaction with Selenium
2 parents a963fbf + 541ca81 commit c382c74

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Created on 2017-10-08
2+
3+
Author : Anish Kachinthaya <anishk23733@gmail.com>
4+
5+
Web scraping made simple with Seleniun
6+
------------------------------------------------------------------
7+
8+
Selenium is a module for browser testing and web scraping.
9+
In this code example, the Chromedriver opens google and enters "do a barrel roll" in the search box.
10+
11+
Modules required:
12+
Selenium
13+
* pip install selenium
14+
Chromedriver (macOS):
15+
* brew install chromedriver
16+
Chromedriver (other):
17+
* download driver from https://sites.google.com/a/chromium.org/chromedriver/downloads and place in PATH
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from selenium import webdriver
2+
from selenium.webdriver.common.by import By
3+
from selenium.webdriver.support.ui import WebDriverWait
4+
from selenium.webdriver.support import expected_conditions as EC
5+
from selenium.common.exceptions import TimeoutException
6+
from selenium.webdriver.common.keys import Keys
7+
import time
8+
9+
driver = webdriver.Chrome()
10+
driver.wait = WebDriverWait(driver, 5)
11+
driver.get("https://www.google.com/")
12+
13+
14+
search_box = driver.find_element_by_xpath('//*[@id="lst-ib"]')
15+
search_box.send_keys("do a barrel roll", Keys.ENTER) # Or whatever you want to fill the text box with
16+
17+
time.sleep(5)
18+
19+
driver.quit()

0 commit comments

Comments
 (0)