1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| from selenium import webdriver from selenium.webdriver.common.by import By from time import sleep import uuid driver = webdriver.Chrome() url = "https://www.baidu.com/" driver.get(url) driver.maximize_window() driver.find_element(By.NAME,"wd").send_keys("bilibili") driver.find_element(By.ID,"su").click() windows = driver.window_handles driver.switch_to.window(windows[-1]) sleep(3) driver.find_element(By.PARTIAL_LINK_TEXT,"哔哩哔哩 (゜-゜)つロ 干杯~-").click() windows = driver.window_handles driver.switch_to.window(windows[-1]) sleep(3) driver.find_element(By.CLASS_NAME,"nav-search-input").send_keys("python") driver.find_element(By.CLASS_NAME,"nav-search-btn").click() sleep(3) windows = driver.window_handles driver.switch_to.window(windows[-1]) print(driver.find_element(By.PARTIAL_LINK_TEXT,"python")) driver.find_element(By.PARTIAL_LINK_TEXT,"黑马程序员python教程").click()
sleep(3) windows = driver.window_handles driver.switch_to.window(windows[-1]) random_filename = str(uuid.uuid4()) src="d:/img/{}.png".format(random_filename) driver.get_screenshot_as_file(src) driver.quit()
|