发布时间: 2023-4-2 文章作者: myluzh 分类名称: Python 朗读文章
import random import time from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By from webdriver_manager.chrome import ChromeDriverManager def chromedriver(): chromedriver_path = ChromeDriverManager().install() return chromedriver_path def main(): option = webdriver.ChromeOptions() option.add_argument('--disable-gpu') # option.add_argument('--incognito') # 无痕模式 # option.add_argument('--headless') # 无头模式 option.add_argument('window-size=320x627') option.add_argument('--start-maximized') option.add_argument('--ignore-certificate-errors') # 忽略证书错误 s = Service(chromedriver()) browser = webdriver.Chrome(options=option, service=s) browser.implicitly_wait(10) browser.get('https://www.baidu.com') time.sleep(1) # browser.find_element(By.XPATH, "//[@id='input_username']").send_keys("1") # browser.find_element(By.XPATH, "//*[@id=\"btn_login\"]").click() if __name__ == "__main__": main()
发表评论