对浏览器进行控制的方法
实际训练代码:
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
# 通过ID来定位
driver = webdriver.Chrome()
driver.maximize_window()
driver.get('http://www.baidu.com')
sleep(3)
driver.find_element(By.ID, 'kw').send_keys("极客时间")
driver.find_element(By.ID, "su").click()
sleep(3)
driver.get_screenshot_as_file('1.结尾截图.png')
print("当前的网址:", driver.current_url)
print("当前的源码:", driver.page_source)
sleep(3)
driver.quit()
from time import sleep
from selenium.webdriver.common.by import By
# 通过ID来定位
driver = webdriver.Chrome()
driver.maximize_window()
driver.get('http://www.baidu.com')
sleep(3)
driver.find_element(By.ID, 'kw').send_keys("极客时间")
driver.find_element(By.ID, "su").click()
sleep(3)
driver.get_screenshot_as_file('1.结尾截图.png')
print("当前的网址:", driver.current_url)
print("当前的源码:", driver.page_source)
sleep(3)
driver.quit()
生命不断追求不止