session登录

###session登录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import requests
from lxml import etree


class Login(object):
def __init__(self):
self.headers = {
'Referer': 'https://github.com/',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36',
'Host': 'github.com'
}
self.login_url = 'https://github.com/login'
self.post_url = 'https://github.com/session'
self.logined_url = 'https://github.com/settings/profile'
self.session = requests.Session()

def token(self):
response = self.session.get(self.login_url, headers=self.headers)
selector = etree.HTML(response.text)
token = selector.xpath('//div//input[2]/@value')
return token

def login(self, email, password):
post_data = {
'commit': 'Sign in',
'utf8': '✓',
'authenticity_token': self.token()[0],
'login': email,
'password': password
}
response = self.session.post(self.post_url, data=post_data, headers=self.headers)
# print(response.text)

if response.status_code == 200:
self.dynamics(response.text)

def dynamics(self, html):
selector = etree.HTML(html)
dynamics = selector.xpath('//a[contains(@class, "user-profile-link")]//strong[contains(@class, "css-truncate-target")]//text()')[0]
print(dynamics)


if __name__ == "__main__":
login = Login()
login.login(email='carmackxiao', password='Vff635241')

###获取图片来破解验证码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
from PIL import Image
from io import BytesIO
from chaojiying import main1

# 取浏览器窗口内全图
def get_big_image(browser):
# browser.execute_script('window.scrollTo(0, 300)')
screenshot = browser.get_screenshot_as_png()
screenshot = Image.open(BytesIO(screenshot))
return screenshot

def get_captha_position(browser, class_str):
wait = WebDriverWait(browser, 5)
captha = wait.until(EC.presence_of_element_located
((By.CSS_SELECTOR, class_str)))
location = captha.location
size = captha.size
x1 = location['x']
y1 = location['y']
width = size['width']
height = size['height']
x2 = x1 + width
y2 = y1 + height
print(x1, y1, x2, y2)
print(width, height)
return (x1, y1, x2, y2)

def get_captcha(browser, class_str):
full_screen_img = get_big_image(browser)
full_screen_img.save('mobile_login.png')

# 获取验证码左上角和右下角坐标
x1, y1, x2, y2 = get_captha_position(browser, class_str)

captha_img = full_screen_img.crop((x1, y1, x2, y2))
captha_img.save('mobile_captha.png')
captha_str = main1('mobile_captha.png')
return captha_str

###短信破解

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# -*- coding: utf-8 -*-
# python3.5

# 易码短信服务平台开放接口范例代码
# 语言版本:python版
# 官方网址:www.51ym.me
# 技术支持QQ:2114927217
# 发布时间:217-12-11

from urllib import parse, request
import time
import re

header_dict = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko'}

# 登陆/获取TOKEN
username = 'carmack' # 账号
password = 'Vff123456' # 密码
url = 'http://api.fxhyd.cn/UserInterface.aspx?action=login&username=' + \
username+'&password='+password
TOKEN1 = request.urlopen(request.Request(
url=url, headers=header_dict)).read().decode(encoding='utf-8')
if TOKEN1.split('|')[0] == 'success':
TOKEN = TOKEN1.split('|')[1]
print('TOKEN是'+TOKEN)
else:
print('获取TOKEN错误,错误代码'+TOKEN1+'。代码释义:1001:参数token不能为空;1002:参数action不能为空;1003:参数action错误;1004:token失效;1005:用户名或密码错误;1006:用户名不能为空;1007:密码不能为空;1008:账户余额不足;1009:账户被禁用;1010:参数错误;1011:账户待审核;1012:登录数达到上限')

TOKEN = '01138099c52f07a264e5d5b27d17fb04e6b9a8dfb501' # 输入TOKEN
# 获取账户信息
url = 'http://api.fxhyd.cn/UserInterface.aspx?action=getaccountinfo&token='+TOKEN+'&format=1'
ACCOUNT1 = request.urlopen(request.Request(
url=url, headers=header_dict)).read().decode(encoding='utf-8')
if ACCOUNT1.split('|')[0] == 'success':
ACCOUNT = ACCOUNT1.split('|')[1]
print(ACCOUNT)
else:
print('获取TOKEN错误,错误代码'+ACCOUNT1)

ITEMID = '694' # 项目编号
EXCLUDENO = '' # 排除号段170_171

# # 获取手机号码
# ITEMID = '694' # 项目编号
# EXCLUDENO = '' # 排除号段170_171
# url = 'http://api.fxhyd.cn/UserInterface.aspx?action=getmobile&token=' + \
# TOKEN+'&itemid='+ITEMID+'&excludeno='+EXCLUDENO
# MOBILE1 = request.urlopen(request.Request(
# url=url, headers=header_dict)).read().decode(encoding='utf-8')
# if MOBILE1.split('|')[0] == 'success':
# MOBILE = MOBILE1.split('|')[1]
# print('获取号码是:\n'+MOBILE)
# else:
# print('获取TOKEN错误,错误代码'+MOBILE1)


def get_mobile():
# 获取手机号码
url = 'http://api.fxhyd.cn/UserInterface.aspx?action=getmobile&token=' + \
TOKEN+'&itemid='+ITEMID+'&excludeno='+EXCLUDENO
MOBILE1 = request.urlopen(request.Request(
url=url, headers=header_dict)).read().decode(encoding='utf-8')
if MOBILE1.split('|')[0] == 'success':
MOBILE = MOBILE1.split('|')[1]
print('获取号码是:\n'+MOBILE)
return MOBILE
else:
print('获取TOKEN错误,错误代码'+MOBILE1)

def release_mobile(MOBILE):
# 释放号码
url = 'http://api.fxhyd.cn/UserInterface.aspx?action=release&token=' + \
TOKEN+'&itemid='+ITEMID+'&mobile='+MOBILE
RELEASE = request.urlopen(request.Request(
url=url, headers=header_dict)).read().decode(encoding='utf-8')
if RELEASE == 'success':
print('号码成功释放')

def get_sms_message(MOBILE):
# 获取短信,注意线程挂起5秒钟,每次取短信最少间隔5秒
WAIT = 100 # 接受短信时长60s
url = 'http://api.fxhyd.cn/UserInterface.aspx?action=getsms&token=' + \
TOKEN+'&itemid='+ITEMID+'&mobile='+MOBILE+'&release=1'
text1 = request.urlopen(request.Request(
url=url, headers=header_dict)).read().decode(encoding='utf-8')
TIME1 = time.time()
TIME2 = time.time()
ROUND = 1
while (TIME2-TIME1) < WAIT and not text1.split('|')[0] == "success":
time.sleep(5)
text1 = request.urlopen(request.Request(
url=url, headers=header_dict)).read().decode(encoding='utf-8')
TIME2 = time.time()
ROUND = ROUND+1

ROUND = str(ROUND)
if text1.split('|')[0] == "success":
text = text1.split('|')[1]
TIME = str(round(TIME2-TIME1, 1))
print('短信内容是'+text+'\n耗费时长'+TIME+'s,循环数是'+ROUND)

# 提取短信内容中的数字验证码
pat = "校验码是 (.*?)。"
IC = 0
IC = re.findall(pat, text)
if IC:
print("验证码是:\n"+IC[0])
return IC[0]
else:
print('获取短信超时,错误代码是'+text1+',循环数是'+ROUND)

'''
# 释放号码
url = 'http://api.fxhyd.cn/UserInterface.aspx?action=release&token=' + \
TOKEN+'&itemid='+ITEMID+'&mobile='+MOBILE
RELEASE = request.urlopen(request.Request(
url=url, headers=header_dict)).read().decode(encoding='utf-8')
if RELEASE == 'success':
print('号码成功释放')

# 提取短信内容中的数字验证码
pat = "[0-9]+"
IC = 0
IC = re.search(pat, text)
if IC:
print("验证码是:\n"+IC.group())
else:
print("请重新设置表达式")
'''

def main():
# mobile = get_mobile()
# print(mobile)
# time.sleep(1)
release_mobile('18272124785')

if __name__ == '__main__':
main()

###超级鹰破解验证码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/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 main1(urlstr):
# print(urlstr)
chaojiying = Chaojiying_Client('carmack', 'Vff635241', '96001')
im = open(urlstr, 'rb').read()
return chaojiying.PostPic(im, 1)['pic_str']


if __name__ == '__main__':
chaojiying = Chaojiying_Client('carmack', 'Vff635241', '96001')
im = open('CaptchaImg.png', 'rb').read()
print(chaojiying.PostPic(im, 1902))

破解猫扑注册验证

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import time
from io import BytesIO
from PIL import Image
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import sms_helper
import captcha_helper

chrome_options = webdriver.ChromeOptions()
# chrome_options.add_argument('--headless')
browser = webdriver.Chrome(chrome_options=chrome_options)

screen_width = 1000
screen_height = 600

browser.set_window_size(screen_width, screen_height)
# 显式等待 针对某个节点的等待
wait = WebDriverWait(browser, 5)

user_name = '一三一世银行卡撒谎'
user_passwd = 'qwer1234'


def get_page():
url = 'http://www.mop.com'
browser.get(url)
button = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, '.mop-registration.mop-top-register')))
button.click()

time.sleep(5)

input_username = wait.until(EC.presence_of_element_located
((By.CSS_SELECTOR, '.register-item.register-nickname .register-input input')))
input_username.clear()
input_username.send_keys(user_name)

input_passwd = wait.until(EC.presence_of_element_located
((By.CSS_SELECTOR, '.register-item.register-password .register-input input')))
input_passwd.clear()
input_passwd.send_keys(user_passwd)

# 取手机号
mobile = sms_helper.get_mobile()
input_mobile = wait.until(EC.presence_of_element_located
((By.CSS_SELECTOR, '.register-item.register-phone .register-input input')))
input_mobile.clear()
input_mobile.send_keys(mobile)

captcha_class_str = '.register-item.register-yzm div.yzm-img'
# 取验证码
captcha = captcha_helper.get_captcha(browser, captcha_class_str)
print(captcha)

# 取验证码输入框
input_captcha = wait.until(EC.presence_of_element_located
((By.CSS_SELECTOR, '.register-item.register-yzm input')))
input_captcha.clear()
input_captcha.send_keys(captcha)

# 点击发送短信
button = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, '.register-msg-btn')))
button.click()

time.sleep(2)
# 提取短信验证码
sms_message = sms_helper.get_sms_message(mobile)
print(sms_message)

# 输入短信验证码
input_sms = wait.until(EC.presence_of_element_located
((By.CSS_SELECTOR, '.register-item.register-msg input')))
input_sms.clear()
input_sms.send_keys(sms_message)

button = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, '.register-item.register-submit .btn-register')))
button.click()

return mobile


def main():
mobile = ''
try:
mobile = get_page()
finally:
print('释放手机号')
# 释放手机号
sms_helper.release_mobile(mobile)


if __name__ == '__main__':
main()