qbao
# -*- coding: utf-8 -*- import Image, cStringIO, webbrowser, re, time, math
import urllib, urllib2, cookielib
from HTMLParser import HTMLParser
import sys
reload(sys)
sys.setdefaultencoding('utf8') class WebHelper:
def __init__(self):
self.cookie = cookielib.CookieJar()
handler = urllib2.HTTPCookieProcessor(self.cookie)
opener = urllib2.build_opener(handler)
urllib2.install_opener(opener) def open(self, path, req_header = None, pd = None):
try:
req = urllib2.Request(path, pd, req_header)
res = urllib2.urlopen(req)
return res
except urllib2.HTTPError, e:
print e.code
return None def showCookie(self):
for item in self.cookie:
print 'Name = ' + item.name
print 'value = ' + item.value def showResponse(self):
content = self.response.read()
return content def showCaptcha(url, header):
#print url
#file = cStringIO.StringIO(c.open(url, header).read())
file = c.open(url, header).read()
local = open("E:\\py_work\\c.jpg", "wb")
local.write(file)
local.close()
img = Image.open("E:\\py_work\\c.jpg")
img.show() #webbrowser.open_new_tab(url) def syscState():
req_header = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0',
'Accept-Language':'en-US,en;q=0.5',
'Accept': '*/*',
'Connection':'keep-alive',
'Host':'bc.qbao.com',
'Referer': 'http://user.qbao.com/syncLoginState.jsp',
}
rlt = c.open("http://bc.qbao.com/account/ucIndex.html", req_header)
print '-------------after sync-------------'
print c.cookie def login(user, passwd): req_header = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language':'en-US,en;q=0.5',
#'Accept-Encoding':'gzip, deflate',
'Connection':'keep-alive',
'Host':'passport.qbao.com',
}
rlt = c.open("https://passport.qbao.com/cas/qianbaoLogin", req_header) print '-------------befor login-------------'
print c.cookie html = rlt.read()
pos = html.find("/cas/captcha.html?pid=");
html = html[pos:]
img_url = html[:html.find('\"')]
showCaptcha("https://passport.qbao.com" + img_url, req_header)
captcha = raw_input("Input captcha !") pos = html.find("name=\"lt\"");
lt = html[pos+17: pos+17+76] pos = html.find("name=\"s_uuid\"");
uuid = html[pos+21: pos+21+36] pos = html.find("name=\'cas_signed\'");
cas_signed = html[pos+25: pos+25+36] login_path = "https://passport.qbao.com/cas/qianbaoLogin" post_data = {
"username" : user,
"password" : passwd,
"j_captcha_response" : captcha,
"lt" : lt,
"_eventId" : "submit",
"s_uuid" : uuid,
"cas_signed" : cas_signed,
} #print post_data
pd = urllib.urlencode(post_data)
rlt = c.open(login_path, req_header, pd)
html = rlt.read()
if html.find("用户登录") >= 0:
print "Login failed!"
else:
print "Login success!"
print html print '-------------After login-------------'
print c.cookie
syscState() def getSharedUrl():
print c.cookie
req_header = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language':'en-US,en;q=0.5',
#'Accept-Encoding':'gzip, deflate',
'Connection':'keep-alive',
'Host':'bc.qbao.com',
}
post_data = {
"state" : "",
"pageNum": "",
"pageSize" : "",
}
pd = urllib.urlencode(post_data)
res = c.open("http://bc.qbao.com/listProduct2.html", req_header, pd)
html = res.read()
#print html
patt = re.compile("(?<=\"id\":)\d*")
ids = patt.findall(html)
print html
print '-------------after get product list-------------'
print c.cookie req_header = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0',
'X-Requested-With' : 'XMLHttpRequest',
'Referer' : '',
'Accept':'application/json, text/javascript, */*; q=0.01',
'Accept-Language':'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
#'Accept-Encoding':'gzip, deflate',
'Connection':'keep-alive',
'Host':'bc.qbao.com',
'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
'Pragma': 'no-cache',
'Cache-Control' : 'no-cache',
} for id in ids:
time.sleep(1)
prod_url = "http://bc.qbao.com/getShareInfo.html"
pos_data = {
"productId" : id,
"r" : "8.100113228429109"
}
req_header['Referer'] = "http://bc.qbao.com/tuan/" + id + ".html"
print req_header
pd = urllib.urlencode(post_data)
res = c.open(prod_url, req_header, pd)
html = res.read()
print html print '-------------befor get Share info-------------'
print c.cookie def visitUser():
url = 'http://user.qbao.com/usercenter/ucIndex.html'
req_header = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language':'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
#'Accept-Encoding':'gzip, deflate',
'Connection':'keep-alive',
'Host':'user.qbao.com',
}
res = c.open(url, req_header)
html = res.read()
print html def visitHome():
req_header = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language':'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
#'Accept-Encoding':'gzip, deflate',
'Connection':'keep-alive',
'Host':'www.qbao.com',
}
res = c.open("http://www.qbao.com/index.html", req_header) c = WebHelper()
visitHome()
login("XXX", "XXX")
#visitUser() getSharedUrl()
qbao的更多相关文章
- 区块链社交APP协议分析:Qbao
- Qbao是什么 - Qbao报文情况 本节我们开始使用Qbao软件,并抓取其报文进行分析. 对APP进行协议分析抓包的一般过程是: 1.打开抓包APP进行抓包: 2.打开APP开始使用: 3.对每 ...
- 【浅析】IMU代码
IMU的代码的引自https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/imumargalgo ...
- Jmeter上传附件EXCEL
1.通过对上传附件接口进行抓包,获取的信息如下: 2.在jmeter脚本中添加http请求,并添加http请求头信息如下: 3.在http请求中添加上传附件的内容如下,由于我上传的是excel,所以M ...
- 工作记录:记一次线上ZK掉线问题排查
目录 问题的发现 zk的情况以及分析 总结 问题的发现 最早问题的发现在于用户提的,用户提出他支付时支付失败,过了一会儿再试就好了,于是翻日志,查询到当时duboo调用出现了下类错误: [TraceI ...
随机推荐
- DFS-深度优先搜索与BFS-广度优先搜索
1.DFS DFS是一个递归过程.(类似于二叉树的前序遍历) 参考:深度优先搜索(Depth-First-Search)精髓 2.BFS 可以理解为按层遍历,借助队列结构来实现.(类似于二叉树的层次遍 ...
- js 给链接 url或href或js、css、图片等解决浏览器缓存
一. 添加时间戳 情况一.链接是常量 var rand = new Date().getTime(); var aLen=document.getElementsByTagName("a&q ...
- Configuring to Debug and Workaround Broken Client Applications
背景:C3P0数据库连接池占满 Configuring to Debug and Workaround Broken Client Applications http://www.mchange.co ...
- Python之通配符--提取文件中的内容并输出
前言:我的学习进度其实没有那么快的,因为现在是网络工程师实习,只有晚上一点时间和周末有空,所以周一到周天的学习进度很慢,今天之所以突然跳到通配符是因为工作需要,大体讲一下我的工作需求:网络工程师就是写 ...
- Leetcode216. Combination Sum III组合总数3
找出所有相加之和为 n 的 k 个数的组合.组合中只允许含有 1 - 9 的正整数,并且每种组合中不存在重复的数字. 说明: 所有数字都是正整数. 解集不能包含重复的组合. 示例 1: 输入: k = ...
- 常用web字体的使用指南
而真正的挑战在于中文字体,由于中文字体组成的特殊性导致其体积过于庞大,除了操作系统内置的字体之外,我们很难在网站上应用其他的字体.在可选性很差的前提之下,如何正确的使用中文字体呢? 首先,以下的字体声 ...
- vue组件与路由的使用步骤
router:根据不同的地址跳转到不同的页面一.vue-router的使用 1.下载路由模块 npm vue-router --save 2.在router.js中 先引入路由 imp ...
- call(this)自记
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- LintCode 链表倒数第n个节点
找到单链表倒数第n个节点,保证链表中节点的最少数量为n. 样例 给出链表 3->2->1->5->null和n = 2,返回倒数第二个节点的值1. 分析:设两个指针 p1和p2 ...
- angular和vue的对比学习之路
vue-ng 打开vue的中文官网一段关于vue的描述 HTML 模板 + JSON 数据,再创建一个 Vue 实例,就这么简单. 那我么再看下angular中文网 AngularJS是为了克服HTM ...