开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用微信号发送消息登录论坛

新人指南 邀请好友注册 - 我关注人的新帖 教你赚取精币 - 每日签到


求职/招聘- 论坛接单- 开发者大厅

论坛版规 总版规 - 建议/投诉 - 应聘版主 - 精华帖总集 积分说明 - 禁言标准 - 有奖举报

查看: 617|回复: 9
收起左侧

[已解决] 验证码图片获取

 关闭 [复制链接]
结帖率:67% (8/12)
发表于 2023-11-29 13:44:27 | 显示全部楼层 |阅读模式   北京市北京市
13精币
https://hetungongying.cn/code?randomStr=11081701235787803
求大神用python写一个代码实现登录时获取验证码图片的完整示例,谢谢https://hetungongying.cn/login
https://hetungongying.cn/code?randomStr=11081701235787803

https://hetungongying.cn/code?randomStr=11081701235787803


最佳答案

查看完整内容

[mw_shl_code=python,true]# This is a sample Python script. import random import string import re # Press Shift+F10 to execute it or replace it with your code. # Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings. import requests def print_hi(name): # Use a breakpoint in the code line below to debug your script. print(f'Hi, {name}') # Press ...

回答提醒:如果本帖被关闭无法回复,您有更好的答案帮助楼主解决,请发表至 源码区 可获得加分喔。
友情提醒:本版被采纳的主题可在 申请荣誉值 页面申请荣誉值,获得 1点 荣誉值,荣誉值可兑换荣誉会员、终身vip用户组。
快捷通道:申请荣誉值无答案申请取消悬赏投诉有答案未采纳为最佳

结帖率:98% (43/44)

签到天数: 8 天

发表于 2023-11-29 13:44:28 | 显示全部楼层   河南省郑州市
[Python] 纯文本查看 复制代码
# This is a sample Python script.
import random
import string
import re

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.

import requests


def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.


def generate_random_number(length):
    # 从数字0-9中随机选择,并生成指定长度的随机数
    return ''.join(random.choices(string.digits, k=length))


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    rand_str = generate_random_number(17)
    img = requests.get('https://hetungongying.cn/code?randomStr=' + rand_str)  # 这里获取到验证码
    with open('downloaded_image.jpg', 'wb') as file:  # 吧验证码保存到本地文件
        file.write(img.content)
    Clientid = requests.get('https://hetungongying.cn/js/app.js')
    pattern = r"Basic\s+([a-zA-Z0-9=]+)"
    rc = Clientid.text
    match = re.findall(pattern, rc)
    Clientid = match[0]
    print(Clientid)
    code = input()
    # 账号密码改成自己的。密码加密自己解决。
    url = 'https://hetungongying.cn/auth/oauth/token?username=15555555555&password=S%2BALIs5ulAlgwrcRLgClrw%3D%3D&randomStr=' + rand_str + '&code=' + code + '&grant_type=password&scope=server'
    print(url)
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.87 Safari/537.36',
        'Authorization': 'Basic ' + Clientid,
        'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6'  # 这个要加,不然返回的就不是中文的了。
    }
    response = requests.get(url, headers=headers)
    print(response)
    print(response.content.decode('utf-8'))
# See PyCharm help at https://www.jetbrains.com/help/pycharm/



Snipaste_2023-11-29_16-20-54.png

评分

参与人数 1荣誉 +1 收起 理由
笨潴 + 1 热心帮助他人,荣誉+1,希望继续努力(*^__^*) 嘻嘻!

查看全部评分

回复

使用道具 举报

结帖率:67% (8/12)
 楼主| 发表于 2023-11-29 13:46:08 | 显示全部楼层   北京市北京市
一般是时间戳,现在这里在前面加了四位,不知道是什么;

补充内容 (2023-11-30 10:13):
{"code":1,"msg":"验证码不合法","data":null,"ok":false}
回复

使用道具 举报

结帖率:99% (121/122)

签到天数: 11 天

发表于 2023-11-29 14:27:27 | 显示全部楼层   贵州省贵阳市
固定不行么?

补充内容 (2023-11-29 14:29):
我看就是4个随机数,最后提交的时候带上就行了吧
回复

使用道具 举报

结帖率:67% (8/12)
 楼主| 发表于 2023-11-29 14:46:46 | 显示全部楼层   北京市北京市
xiaoyu1986 发表于 2023-11-29 14:27
固定不行么?

补充内容 (2023-11-29 14:29):

不行,加了试过
回复

使用道具 举报

结帖率:67% (8/12)
 楼主| 发表于 2023-11-29 14:50:13 | 显示全部楼层   北京市北京市

{"timestamp":"2023-11-29 14:48:48","path":"/code","status":404,"error":"Not Found","message":null,"requestId":"171d935e-1633445"}
回复

使用道具 举报

结帖率:78% (7/9)

签到天数: 13 天

发表于 2023-11-29 15:23:26 | 显示全部楼层   河南省郑州市
[Python] 纯文本查看 复制代码
resp = requests.get("https://hetungongying.cn/code?randomStr=16441701242159040")
resp.content

resp = requests.post("https://hetungongying.cn/code?randomStr=16441701242159040")
print(resp.text)
# {"timestamp":"2023-11-29 15:22:31","path":"/code","status":404,"error":"Not Found","message":null,"requestId":"65d05e4e-1633836"}

评分

参与人数 1好评 +1 精币 +2 收起 理由
aipincun + 1 + 2 支持开源~!感谢分享

查看全部评分

回复

使用道具 举报

结帖率:67% (8/12)
 楼主| 发表于 2023-11-29 16:17:00 | 显示全部楼层   北京市北京市
一线之隔 发表于 2023-11-29 15:23
[mw_shl_code=python,true]resp = requests.get("https://hetungongying.cn/code?randomStr=16441701242159 ...

这种方式,下载的图片打不开,返回的是404哦
回复

使用道具 举报

结帖率:78% (7/9)

签到天数: 13 天

发表于 2023-11-29 16:37:18 | 显示全部楼层   河南省郑州市
aipincun 发表于 2023-11-29 16:17
这种方式,下载的图片打不开,返回的是404哦

不知道你在说什么,哪里有404,那就是个随机数而已
0.png

评分

参与人数 1好评 +1 精币 +2 收起 理由
aipincun + 1 + 2 支持开源~!感谢分享

查看全部评分

回复

使用道具 举报

结帖率:78% (7/9)

签到天数: 13 天

发表于 2023-11-29 16:39:08 | 显示全部楼层   河南省郑州市
怕不是你写成post返回的404
[Python] 纯文本查看 复制代码
const randomLenNum = (len, date) => {
  let random = '';
  random = Math.ceil(Math.random() * 1000000000000).toString().substring(0, len || 4);
  if (date) random = random + Date.now();
  return random;
};
1.png
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 致发广告者

发布主题 收藏帖子 返回列表

sitemap| 易语言源码| 易语言教程| 易语言论坛| 诚聘英才| 易语言模块| 手机版| 广告投放| 精易论坛
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
论坛帖子内容仅用于技术交流学习和研究的目的,严禁用于非法目的,否则造成一切后果自负!如帖子内容侵害到你的权益,请联系我们!
防范网络诈骗,远离网络犯罪 违法和不良信息举报电话0663-3422125,QQ: 800073686,邮箱:800073686@b.qq.com
Powered by Discuz! X3.4 揭阳市揭东区精易科技有限公司 ( 粤ICP备12094385号-1) 粤公网安备 44522102000125 增值电信业务经营许可证 粤B2-20192173

快速回复 返回顶部 返回列表