Selenium 控制浏览器操作
方法 |
操作 |
使用场景 |
实现代码 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from selenium import webdriver import time def window_start(): driver = webdriver.Edge() url = 'https://www.cnblogs.com/' driver.get(url) time.sleep(10) driver.quit() if __name__ == '__main__': window_start()
from selenium import webdriver import time def window_refresh(): driver = webdriver.Edge() url = 'https://www.cnblogs.com/' driver.get(url) time.sleep(5) driver.refresh() time.sleep(5) driver.quit() if __name__ == '__main__': window_refresh()
from selenium import webdriver import time from selenium.webdriver.common.by import By def window_back(): driver = webdriver.Edge() url = 'https://www.cnblogs.com/' driver.get(url) time.sleep(5) driver.find_element(By.CLASS_NAME,'navbar-anonymous').click() time.sleep(5) driver.back() time.sleep(5) driver.quit() if __name__ == '__main__': window_back()
from selenium import webdriver import time from selenium.webdriver.common.by import By def window_max(): driver = webdriver.Edge() url = 'https://www.cnblogs.com/' driver.get(url) driver.maximize_window() time.sleep(5) driver.quit() if __name__ == '__main__': window_max()
from selenium import webdriver import time from selenium.webdriver.common.by import By def window_min(): driver = webdriver.Edge() url = 'https://www.cnblogs.com/' driver.get(url) driver.minimize_window() time.sleep(5) driver.quit() if __name__ == '__main__': window_min()