[Python] Introduction to web scraping | Summary of methods that can be used with webdriver
[Python] Introduction to web scraping | Summary of methods that can be used with webdriver
List of major methods available in webdriver for selenium module
** ■ Methods that can be used without specifying elements **
--get (opens the specified page)
--back
--forward
--refresh
--current_url (get current URL)
--title (Get page title)
--page_source (Get page source)
--close (closes the current window)
--quit (close all windows)
--maximize_window
** ■ Element specification method **
** ▼ 1 element **
- find_element_by_id
- find_element_by_class_name
- find_element_by_css_selector
- find_element_by_name
- find_element_by_tag_name
- find_element_by_xpath
- find_element_by_link_text
** ▼ Multiple elements **
- find_elements_by_class_name
- find_elements_by_css_selector
- find_elements_by_xpath
- find_elements_by_id
- find_elements_by_link_text
- find_elements_by_tag_name
** ■ Method used in combination with element specification **
--click (click an element)
--send_keys (text input)
--getText
--get_attribute
--is_enabled (determines if the element is enabled)
--is_selected (whether the element is selected)
How to use
Install webdriver for selenium module.
Used as a set with webdriver.Chrome ('chromedriver.exe').
(* The chromedriver.exe file is in the same hierarchy as the source code)
python
from selenium import webdriver
browser = webdriver.Chrome('chromedriver.exe')
### ■ Methods that can be used without specifying elements
Execute for browser object.
Example: browser.get (https: // ~)
└ Open the specified URL
### ■ Method of element specification
Example: `browser.find_element_by_id ('headline')`
└ Get the element that contains the specified element
└ In the above example id ='headline'
### ■ Method used in combination with element specification
Example 1: `driver.find_element_by_id ('btn'). click ()`
└ Execute method for specified element
└ In the above example, click the element with id ='btn'
Example 2:
driver.find_element_by_id('useName').send_keys("myname")
└ In the above example, enter "myname" in text in the element of id ='useName'