python web crawler study notes Four Selenium browser and operating elements

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/bowei026/article/details/90729415

First, the basics

Selenium operating elements each have eight find_element_by_xxx find_elements_by_xxx targeting elements and methods:
find_element_by_id
find_element_by_name 
find_element_by_class_name
find_element_by_tag_name
find_element_by_link_text
find_element_by_partial_link_text
find_element_by_css_selector
find_element_by_xpath
 

Operating element (or attribute Method)
Clear Clear contents
click click
submit similar to the click
send_keys typing
get_attribute getting a property value
text text
size dimensions
is_displayed is displayed
if available is_enabled

Operating a browser
set_window_size
maximize_window
the Back forward
forward back
refresh refresh
title title
current_url address


Second, the example

Example 1

from selenium import webdriver

browser = webdriver.Chrome()
browser.get('http://www.baidu.com')

input = browser.find_element_by_id("kw")
# input.send_keys("hello")
# input = browser.find_element_by_name("wd")
# input.send_keys("centyun")
# browser.find_element_by_id("su").click()

input_editor = browser.find_element_by_class_name("s_ipt")
input_editor.send_keys("python")

Example 2

from selenium import webdriver

browser = webdriver.Chrome()
browser.maximize_window()
browser.get('http://www.baidu.com')
print(browser.title)
browser.quit()

This concludes this article, it may be more concerned about the number of public and personal micro signal:

Guess you like

Origin blog.csdn.net/bowei026/article/details/90729415