File tree Expand file tree Collapse file tree
recipes/Python/Selenium_For_Web_Scraping Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments