码迷,mamicode.com
首页 > 其他好文 > 详细

登录中国人民银行征信中心

时间:2017-09-24 23:30:14      阅读:1996      评论:0      收藏:0      [点我收藏+]

标签:中国人   str   报告   ken   token   debug   reg   word   print   

# coding=utf-8
import requests
import time
import os
import re
from lxml import etree
import warnings
warnings.filterwarnings("ignore")

from Logger import Logger
logger=Logger(logname=‘logcrcc.txt‘, loglevel=1, logger="crcc").getlog()
class Crcc(object):
headerx={
‘Host‘:‘ipcrs.pbccrc.org.cn‘,
‘User-Agent‘:‘Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36‘,
}
def __init__(self,username,passwd):
self.username=username
self.passwd=passwd
self.ss=requests.Session()

def loginreg(self):
self.headerx.update({‘Referer‘: ‘https://ipcrs.pbccrc.org.cn/‘,})
self.ss.get(‘https://ipcrs.pbccrc.org.cn/login.do?method=initLogin‘, verify=False,headers=self.headerx)
url=‘https://ipcrs.pbccrc.org.cn/page/login/loginreg.jsp‘
resp=self.ss.get(url, verify=False,headers=self.headerx)
print resp.content.decode(‘gbk‘)
self.token_value=re.search(‘taglib.html.TOKEN" value="(.*?)"> ‘,resp.content).group(1)
self.verification_code_url=re.search(‘<img src="/(.*?)" id="imgrc"‘,resp.content).group(1)
self.date=re.search(‘<input type="hidden" name="date" value="(.*?)"/>‘,resp.content).group(1)
print self.token_value,self.verification_code_url,self.date,

def get_verification_code(self):

self.headerx.update({
‘Referer‘: ‘https://ipcrs.pbccrc.org.cn/page/login/loginreg.jsp‘,
})
url=‘https://ipcrs.pbccrc.org.cn/%s‘%self.verification_code_url
resp=self.ss.get(url,verify=False,headers=self.headerx)
if not os.path.exists(‘pictures‘):
os.mkdir(‘pictures‘)
self.pic_name=‘pictures/%s.jpg‘%str(time.time()).replace(‘.‘,‘‘)
try:
with open(self.pic_name,‘wb‘) as f:
f.write(resp.content)
print self.pic_name
os.system(self.pic_name.replace(‘/‘,‘\\‘)) #TODO win下面\
except Exception,e:
logger.debug(u‘保存图片出错,原因是:%s‘%(str(e)))

def login(self):
self.get_verification_code()
verification_code=raw_input(‘请输入验证码:‘)
url=‘https://ipcrs.pbccrc.org.cn/login.do‘
datax={
‘org.apache.struts.taglib.html.TOKEN‘:self.token_value,
‘method‘:‘login‘,
‘date‘:self.date, #self.date,
‘loginname‘:self.username,
‘password‘:self.passwd,
‘_@IMGRC@_‘:verification_code #verification_code,
}
self.headerx.update({
‘Referer‘:‘https://ipcrs.pbccrc.org.cn/login.do‘,
})
print datax
resp=self.ss.post(url,datax,headers=self.headerx,verify=False)
print resp.content.decode(‘gbk‘)
print self.ss.get(‘https://ipcrs.pbccrc.org.cn/welcome.do‘,headers=self.headerx).content.decode(‘gbk‘)

crccx=Crcc(‘ydfxxx‘,‘123456789yyy‘)
#crccx.get_verification_code()
crccx.loginreg()
crccx.login()


登录成功后,welcome页面可以显示今天第几次登录,说明登录成功了。登录成功后,授权爬取个人信用信息提示,个人信用信息概要,个人信用报告这三种信用信息。

登录中国人民银行征信中心

标签:中国人   str   报告   ken   token   debug   reg   word   print   

原文地址:http://www.cnblogs.com/ydf0509/p/7589109.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!