python实现手机号获取短信验证码 | 对接打码平台

向阳-Y. 2021-11-25 09:12:21
Python 手机 实现 获取 手机号

前言

本篇文章主要讲了如何利用python自动注册网站(自动识别验证码)
在这里插入图片描述

ID在用户中心最下面的软件ID里获取
识别类型在“价格体系”中查看
首先需要花1块钱到超级鹰打码平台上买点题分(1块钱1000提分,可以打100次)
超级鹰官网http://www.chaojiying.com

短信获取.py

import time
import requests
from chaojiying import Chaojiying_Client #调用chaojiying.py文件中的函数
"""如果请求的网站需要时间戳,则使用以下代码获取,不需要则忽略"""
def get_time():
"""时间戳的获取"""
now_time=str(int(time.time()*1000))
#print("当前的时间戳为:",now_time)
return now_time
#准备请求参数
headers={
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0'}
time_one=get_time()
#发送图片验证码请求
img_url='https://my.guidechem.com/captcha/captcha-image.action?random='+ time_one
response=requests.get(url=img_url,headers=headers)#获取验证码图片
img_data=response.content #提取二进制数据
#保存验证码图片
with open('yzm.jpg',mode='wb') as f: #b表示二进制
f.write(img_data)
# 识别验证码(对接打码平台)
code=Chaojiying_Client('超级鹰用户名', '超级鹰密码', '超级鹰id').run() #这里的run就是在chaojiyin.py中自定的函数
print('当前验证码结果为',code)
#两次请求要保证是同一个用户cookie<用户的身份标识>
cookieJar=response.cookies
cookies=cookieJar.get_dict() #把cookieJar转换字典
#发送短信验证的请求参数,这里的post参数是根据网站情况而变的
data={

'mobileNo': 手机号,
'captcha': code
}
# 请求发送验证码
code_url='https://my.guidechem.com/sms/sendRegCode.action'
response_2=requests.post(url=code_url,headers=headers,data=data,cookies=cookies)
print(response_2.json()) #打印返回值,查看是否发送成功

chaojiying.py(超级鹰接口文件)

获取途径,http://www.chaojiying.com
在这里插入图片描述
在这里插入图片描述

chaojiying操作过程如下:

1.在下载后的py文件中新定义一个函数run

 def run(self):
chaojiying = Chaojiying_Client('账号', '密码', 'ID')
im = open('yzm.jpg', 'rb').read()
result=chaojiying.PostPic(im,1004)#1004为识别类型
return result['pic_str']

2.修改下面的内容,yzm.jpg是本地的验证码图片文件

if __name__ == '__main__':
chaojiying = Chaojiying_Client('账号', '密码', 'ID') #用户中心>>软件ID 生成一个替换 96001
im = open('yzm.jpg', 'rb').read() #本地图片文件路径 来替换 a.jpg 有时WIN系统须要//
result=chaojiying.PostPic(im,1004)
print(result['pic_str'])

其他细节省略…


最后chaojiying.py文件内容如下:

#!/usr/bin/env python
# coding:utf-8
import requests
from hashlib import md5
class Chaojiying_Client(object):
def __init__(self, username, password, soft_id):
self.username = username
password = password.encode('utf8')
self.password = md5(password).hexdigest()
self.soft_id = soft_id
self.base_params = {

'user': self.username,
'pass2': self.password,
'softid': self.soft_id,
}
self.headers = {

'Connection': 'Keep-Alive',
'User-Agent': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
}
def PostPic(self, im, codetype):
""" im: 图片字节 codetype: 题目类型 参考 http://www.chaojiying.com/price.html """
params = {

'codetype': codetype,
}
params.update(self.base_params)
files = {
'userfile': ('ccc.jpg', im)}
r = requests.post('http://upload.chaojiying.net/Upload/Processing.php', data=params, files=files, headers=self.headers)
return r.json()
def ReportError(self, im_id):
""" im_id:报错题目的图片ID """
params = {

'id': im_id,
}
params.update(self.base_params)
r = requests.post('http://upload.chaojiying.net/Upload/ReportError.php', data=params, headers=self.headers)
return r.json()
def run(self):
chaojiying = Chaojiying_Client('账号', '密码', 'ID') #用户中心>>软件ID 生成一个替换 96001
im = open('yzm.jpg', 'rb').read() #本地图片文件路径 来替换 a.jpg 有时WIN系统须要//
result=chaojiying.PostPic(im,1004)
return result['pic_str']
if __name__ == '__main__':
chaojiying = Chaojiying_Client('账号', '密码', 'ID') #用户中心>>软件ID 生成一个替换 96001
im = open('yzm.jpg', 'rb').read() #本地图片文件路径 来替换 a.jpg 有时WIN系统须要//
result=chaojiying.PostPic(im,1004)
print(result['pic_str']) #1902 验证码类型 官方网站>>价格体系 3.4+版 print 后要加()

最后运行"短信获取.py"执行结果:
在这里插入图片描述

版权声明
本文为[向阳-Y.]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_45951067/article/details/121516547

  1. The difference between single quotation marks, double quotation marks, three single quotation marks and three double quotation marks in Python
  2. Python exercise (11.7)
  3. python11~20
  4. Matlab, python example exercise -- Day2
  5. Matlab, python example exercise -- Day1
  6. White Python road -- Day5
  7. Python正则表达式选择字符
  8. The white way of Python -- day4 (I can't learn it gradually)
  9. The white way of Python -- Day3
  10. The white Python road -- Day2
  11. The white way of Python -- Day1
  12. Difference between input in python2 and python3
  13. Exception handling in Python
  14. Metaclass and singleton pattern of Python
  15. Python methods and functions
  16. Python regular expression select Characters
  17. Introduction to Python object-oriented reflection and built-in methods
  18. Object oriented composition of Python
  19. Python object oriented polymorphism
  20. Object oriented encapsulation of Python
  21. Object oriented inheritance in Python
  22. Python Software Development Directory
  23. Python package
  24. Python module
  25. Python is process oriented and functional
  26. Python function recursion
  27. Python generator
  28. Python iterator
  29. Python decorator
  30. Python function closure
  31. Python namespace and scope
  32. Python function
  33. Python file processing
  34. Python data type
  35. Process control of Python
  36. Garbage collection mechanism of Python
  37. Python: the field notes of dtype = 'object' can also be arranged in ascending and descending order
  38. . value in pandas_ Usage of counts()
  39. 202111 | some hands-on practice of Python time function
  40. 202111 | in Python, timestamp, time string and real date time are converted to each other
  41. Pandas draws line chart, bar chart and bar chart
  42. Exploration and practice of easy transformation between various data structures in Python
  43. A simple practice of Python list generation
  44. Use Python to guess the number of machines and judge the number of guesses
  45. Question about Python: did you learn Python
  46. 20210928 | Python case: building tax calculation function
  47. Python basic syntax collation
  48. Some small accumulation of writing programs in python (4)
  49. Some small accumulation of writing programs in python (3)
  50. Python leak detection tips (3)
  51. Python leak detection tips (2)
  52. Python leak detection tips (1)
  53. Python foundation and MySQL Foundation
  54. Some small accumulation of writing programs in python (2)
  55. Some small accumulation of writing programs in Python
  56. Python 3.7.3 + cuda9.2 installing Python
  57. Python knowledge used to write programs
  58. Python installation + vscode configuration Python environment
  59. Some small problems during Python installation
  60. Answer and Q & A of Python practice introduction course