一、说明
selenium操作
二、代码
def get_login(): chrome_options = webdriver.ChromeOptions() extension_path = r'C:\Program Files (x86)\Google\Chrome\Application\maozhua.crx' chrome_options.add_extension(extension_path) driver_path = r"C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe" browser = webdriver.Chrome(executable_path=driver_path, options=chrome_options) browser.maximize_window() time.sleep(2) browser.get("https://www.mingrisoft.com/Book/brochure_detail/id/201.html") time.sleep(1) # 登陆操作 denglu = browser.find_element_by_xpath('//*[@id="toolbarViewerRight"]/div[1]/div/div/div/a[1]') # 直接点击 # browser.find_element_by_xpath('//*[@id="toolbarViewerRight"]/div[1]/div/div/div/a[1]').click() denglu.click() user_name = browser.find_element_by_xpath('//*[@id="username"]') user_name.send_keys('用户名') time.sleep(0.5) pass_words = browser.find_element_by_xpath('//*[@id="passwords"]') pass_words.send_keys('密码') # 滑动条 qapTcha = browser.find_element_by_xpath('//*[@id="QapTcha"]/div[1]/div[1]') # 实例化一个action对象 action = ActionChains(browser) # perform()用来执行ActionChains中存储的行为 action.click_and_hold(qapTcha).perform() action.reset_actions() action.move_by_offset(300, 0).perform() action.release() action.perform() time.sleep(0.5) denglu_click = browser.find_element_by_xpath('//*[@id="login_form"]/div/div[5]/input') denglu_click.click()