验证码自动识别登录

# 1.因为用户名和密码和验证码的name都是随机的,所以我们先要获取网页源代码,
#然后提取出其中的name值
# 2.获取到name和once的值以后,再通过调用https://www.v2ex.com/sigin接口,把数据
#通过post请求发送过去
# 3.还需要使用云打码平台去自动识别验证码
import requests
from lxml import etree

from 反爬虫攻防实战.验证码识别.fateadm_api import recognize_captcha

login_url = "https://www.v2ex.com/signin"
settings_url = ''
headers = {
    "user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
    "referer": "https://www.v2ex.com/signin",

}
session = requests.Session()
resp = session.get(login_url,headers=headers)
html = resp.text
parser = etree.HTML(html)
inputs = parser.xpath("//form[@action='/signin']//input")
userInput = inputs[0]
passwordInput = inputs[1]
captchaInput = inputs[2]
onceInput = inputs[3]
# for input in inputs:
#     input_text = etree.tostring(input)
#     print(input_text)
#     print("="*30)
userName = userInput.get('name')
passwordName = passwordInput.get('name')
captchaName = captchaInput.get('name')
onceValue = onceInput.get('value')

data = {
    userName:'Lauquan',
    passwordName:'你的密码',
    "once":onceValue,
    'next':'/'
}

captcha_url = "https://www.v2ex.com/_captcha?once="+onceValue
imgResp = session.get(captcha_url,headers=headers)
with open("captcha.png",'wb') as fp:
    fp.write(imgResp.content)

# captchaValue = input("请输入验证码:")
captchaValue  = recognize_captcha("captcha.png","20900")

data[captchaName] = captchaValue

loginResp = session.post(login_url,headers=headers,data=data)
settingsResp = session.get(settings_url,headers=headers)
print(settingsResp.text)
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值