一、说明

selenium操作

二、代码

  1. def get_login():
  2. chrome_options = webdriver.ChromeOptions()
  3. extension_path = r'C:\Program Files (x86)\Google\Chrome\Application\maozhua.crx'
  4. chrome_options.add_extension(extension_path)
  5. driver_path = r"C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe"
  6. browser = webdriver.Chrome(executable_path=driver_path, options=chrome_options)
  7. browser.maximize_window()
  8. time.sleep(2)
  9. browser.get("https://www.mingrisoft.com/Book/brochure_detail/id/201.html")
  10. time.sleep(1)
  11. # 登陆操作
  12. denglu = browser.find_element_by_xpath('//*[@id="toolbarViewerRight"]/div[1]/div/div/div/a[1]')
  13. # 直接点击
  14. # browser.find_element_by_xpath('//*[@id="toolbarViewerRight"]/div[1]/div/div/div/a[1]').click()
  15. denglu.click()
  16. user_name = browser.find_element_by_xpath('//*[@id="username"]')
  17. user_name.send_keys('用户名')
  18. time.sleep(0.5)
  19. pass_words = browser.find_element_by_xpath('//*[@id="passwords"]')
  20. pass_words.send_keys('密码')
  21. # 滑动条
  22. qapTcha = browser.find_element_by_xpath('//*[@id="QapTcha"]/div[1]/div[1]')
  23. # 实例化一个action对象
  24. action = ActionChains(browser)
  25. # perform()用来执行ActionChains中存储的行为
  26. action.click_and_hold(qapTcha).perform()
  27. action.reset_actions()
  28. action.move_by_offset(300, 0).perform()
  29. action.release()
  30. action.perform()
  31. time.sleep(0.5)
  32. denglu_click = browser.find_element_by_xpath('//*[@id="login_form"]/div/div[5]/input')
  33. denglu_click.click()