First, get all the information about the current page
1. Image information includes the image name, image size and other information
2. Simply print out the picture information (image.text image.size image.tag_name)
Second, the acquisition of page elements href attribute (id empathy)
1. Get all of the current page link information (to Baidu home page, for example)
2. The use of the for loop, and then use get_attribute ( 'href')
3. Then it can be printed out
Third, a screenful of information interception
1. The use of get_screenshot_file () to take a screenshot
Fourth, the test script
1. The above three code written together as follows:
#coding:utf-8
from selenium import webdriver
import time
driver=webdriver.Firefox()
driver.maximize_window()
driver.implicitly_wait(8)
driver.get("https://www.baidu.com/")
for image in driver.find_elements_by_tag_name ( "img"): # get information about the current picture page
print image.text
print image.size
print image.tag_name
print "================================"
time.sleep(2)
for link in driver.find_elements_by_xpath ( "// * [@ href]"): # Get the current page href
print link.get_attribute('href')
print "================================"
for id in driver.find_elements_by_xpath ( "// * [@ id]"): # get current page id
print id.get_attribute('id')
print "================================"
driver.get_screenshot_as_file ( "E: \\ work_study \\ One.png") # intercepted picture (full screen) of the current page. Brackets to hold the path to the path to the local computer above, can be arbitrarily set.
driver.quit()