python手工打码_python --爬虫 打码登陆

云平台打码 http://www.yundama.com/

账号:zhenghongyu 密码: 381650127yhz

豆瓣打码:

import http.client, mimetypes, urllib, json, time, requests

######################################################################

class YDMHttp:

apiurl = 'http://api.yundama.com/api.php'

username = ''

password = ''

appid = ''

appkey = ''

def __init__(self, username, password, appid, appkey):

self.username = username

self.password = password

self.appid = str(appid)

self.appkey = appkey

def request(self, fields, files=[]):

response = self.post_url(self.apiurl, fields, files)

response = json.loads(response)

return response

def balance(self):

data = {'method': 'balance', 'username': self.username, 'password': self.password, 'appid': self.appid,

'appkey': self.appkey}

response = self.request(data)

if (response):

if (response['ret'] and response['ret'] < 0):

return response['ret']

else:

return response['balance']

else:

return -9001

def login(self):

data = {'method': 'login', 'username': self.username, 'password': self.password, 'appid': self.appid,

'appkey': self.appkey}

response = self.request(data)

if (response):

if (response['ret'] and response['ret'] < 0):

return response['ret']

else:

return response['uid']

else:

return -9001

def upload(self, filename, codetype, timeout):

data = {'method': 'upload', 'username': self.username, 'password': self.password, 'appid': self.appid,

'appkey': self.appkey, 'codetype': str(codetype), 'timeout': str(timeout)}

file = {'file': filename}

response = self.request(data, file)

if (response):

if (response['ret'] and response['ret'] < 0):

return response['ret']

else:

return response['cid']

else:

return -9001

def result(self, cid):

data = {'method': 'result', 'username': self.username, 'password': self.password, 'appid': self.appid,

'appkey': self.appkey, 'cid': str(cid)}

response = self.request(data)

return response and response['text'] or ''

def decode(self, filename, codetype, timeout):

cid = self.upload(filename, codetype, timeout)

if (cid > 0):

for i in range(0, timeout):

result = self.result(cid)

if (result != ''):

return cid, result

else:

time.sleep(1)

return -3003, ''

else:

return cid, ''

def report(self, cid):

data = {'method': 'report', 'username': self.username, 'password': self.password, 'appid': self.appid,

'appkey': self.appkey, 'cid': str(cid), 'flag': '0'}

response = self.request(data)

if (response):

return response['ret']

else:

return -9001

def post_url(self, url, fields, files=[]):

for key in files:

files[key] = open(files[key], 'rb');

res = requests.post(url, files=files, data=fields)

return res.text

######################################################################

import requests

import urllib.request

from bs4 import BeautifulSoup

headers = {

'Referer': 'https://www.baidu.com/link?url=N6aTegg-CdRmi4aTkTmQmRzJE6tRkZzRO-ugJmD-uTuBBi6G7gJi7Qv-hmKtcao5&wd=&eqid=ae67fe3d000188b8000000025b95e54a',

'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36'

}

html = requests.get('https://www.douban.com/', headers=headers).text

soup = BeautifulSoup(html, 'html.parser')

headers = {

'Host': 'www.douban.com',

'Origin': 'https://www.douban.com',

'Referer': 'https://www.douban.com/',

'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36'

}

if soup.find('img', attrs={'class': 'captcha_image'}) is None: #  登陆没有验证码

data = {

'source': 'index_nav',

'form_email': '1753442757 @ qq.com',

'form_password': 'zcl19980901',

}

s = requests.Session()

responses = s.post('https://www.douban.com/accounts/login', data=data, headers=headers).text

print(responses)

print(s.get('https://www.douban.com/', headers=headers).text)

else: # 登陆有验证码

img_url = soup.find('img', attrs={'class': 'captcha_image'}).get('src')

urllib.request.urlretrieve(img_url, './getimage.jpg')

id = img_url.split('id=')[-1].split('&')[0]

# 用户名

username = 'zhenghongyu'

# 密码

password = '381650127yhz'

# 软件ID,开发者分成必要参数。登录开发者后台【我的软件】获得!

appid = 1

# 软件密钥,开发者分成必要参数。登录开发者后台【我的软件】获得!

appkey = '22cc5376925e9387a23cf797cb9ba745'

# 图片文件

filename = 'getimage.jpg'

# 验证码类型,# 例:1004表示4位字母数字,不同类型收费不同。请准确填写,否则影响识别率。在此查询所有类型 http://www.yundama.com/price.html

codetype = 3000

# 超时时间,秒

timeout = 60

# 检查

if (username == 'username'):

print('请设置好相关参数再测试')

else:

# 初始化

yundama = YDMHttp(username, password, appid, appkey)

# 登陆云打码

uid = yundama.login();

print('uid: %s' % uid)

# 查询余额

balance = yundama.balance();

print('balance: %s' % balance)

# 开始识别,图片路径,验证码类型ID,超时时间(秒),识别结果

cid, result = yundama.decode(filename, codetype, timeout);

print('cid: %s, result: %s' % (cid, result))

data = {

'source': 'index_nav',

'form_email': '[email protected]',

'form_password': 'zcl19980901',

'captcha-solution': result,

'captcha-id': id

}

print(data)

s = requests.Session()

responses = s.post('https://www.douban.com/accounts/login', data=data, headers=headers).text

print(s.get('https://www.douban.com/', headers=headers).text)

你可能感兴趣的:(python手工打码)