The new selenium analogue Login know almost

About parameter request error 1001

  • Because of the known anti-climb almost mechanisms can be detected selenium is denied access script 1001
  • Results windows.navigator.webdriver browser chrome is Ture, and when the normal use of the browser and False
  • Just set it to developer mode, to prevent major sites identified using Selenium
#设置为开发者模式
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-automation'])
b=webdriver.Chrome(executable_path='C:\\Desktop\\chromedriver.exe',options=options)

step

  1. Get Link
  2. The Xpath or acquiring position css
  3. Input parameters
  4. Click to Login

Code

from selenium import webdriver
from scrapy.selector import Selector

# 进入开发者模式
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-automation'])
b=webdriver.Chrome(executable_path='C:\\Users\\23607\\Desktop\\py\\chromedriver.exe',options=options)

b.get('https://www.zhihu.com/signin?next=%2F')
#切换到密码登录
b.find_element_by_xpath('//*[@id="root"]/div/main/div/div/div[2]/div/form/div[1]/div[2]').click()

#根据css获取位置并输入账号密码
b.find_element_by_css_selector('.SignFlow-accountInputContainer div input[name="username"]').send_keys('账号')
b.find_element_by_css_selector('.SignFlow-password div div input[name="password"]').send_keys('密码')
#根据xpath获取相应位置并点击登录
b.find_element_by_xpath('//*[@id="root"]/div/main/div/div/div[2]/div/form/button').click()

 b.quit()
Released nine original articles · won praise 9 · views 2951

Guess you like

Origin blog.csdn.net/Rice__/article/details/99699660