老师您好, 我登录拉钩网的时候,登录按钮Click无法点击,手动点击登录也不行!代码如下

来源:7-5 网页302之后的模拟登录和cookie传递(网站需要登录时学习本视频教程)

荼灬

2021-05-21

import undetected_chromedriver as uc
from selenium import webdriver
from selenium.webdriver.common.keys import Keys 
import time

user = "*******"
password = "*********"
url = "https://passport.lagou.com/login/login.html"

uc.TARGET_VERSION = 90
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--disable-gpu') 
chrome_options.add_argument('--disable-dev-shm-usage')

driver = uc.Chrome(options=chrome_options)

driver.get(url)

# 输入账号
driver.find_element_by_xpath("//form[@class='active']/div[1]//input[@class='input input_white HtoC_JS']").send_keys(Keys.CONTROL+"a")
driver.find_element_by_xpath("//form[@class='active']/div[1]//input[@class='input input_white HtoC_JS']").send_keys(user)

# 输入密码
driver.find_element_by_xpath("//form[@class='active']/div[2]//input[@class='input input_white HtoC_JS']").send_keys(Keys.CONTROL+"a")
driver.find_element_by_xpath("//form[@class='active']/div[2]//input[@class='input input_white HtoC_JS']").send_keys(password)

# 点击登录按钮
driver.find_element_by_xpath("//div[@class='input_item btn_group clearfix sense_login_password']/input").click()

time.sleep(30)
写回答

1回答

bobby

2021-05-24

import undetected_chromedriver.v2 as uc
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

user = "*******"
password = "*****"
url = "https://passport.lagou.com/login/login.html"

uc.TARGET_VERSION = 90
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-dev-shm-usage')

driver = uc.Chrome(options=chrome_options)

driver.get(url)

# 输入账号
driver.find_element_by_xpath("//form[@class='active']/div[1]//input[@class='input input_white HtoC_JS']").send_keys(Keys.CONTROL+"a")
driver.find_element_by_xpath("//form[@class='active']/div[1]//input[@class='input input_white HtoC_JS']").send_keys(user)

# 输入密码
driver.find_element_by_xpath("//form[@class='active']/div[2]//input[@class='input input_white HtoC_JS']").send_keys(Keys.CONTROL+"a")
driver.find_element_by_xpath("//form[@class='active']/div[2]//input[@class='input input_white HtoC_JS']").send_keys(password)

# 点击登录按钮
driver.find_element_by_xpath("//div[@class='input_item btn_group clearfix sense_login_password']/input").click()

time.sleep(30)

拷贝这个代码运行试试

0
2
bobby
回复
荼灬
好的,这也是一个很重要的发现,你可以再进一步确定一下是chrome_options中哪个参数引起的就可以猜测到拉勾网是如何排查的
2021-05-25
共2条回复

Scrapy打造搜索引擎 畅销4年的Python分布式爬虫课

带你彻底掌握Scrapy,用Django+Elasticsearch搭建搜索引擎

5831 学习 · 6293 问题

查看课程