Python2.7获取QQ照片墙
通过wireshark抓电脑版QQ的http数据包得到的结果
接口调用:
http://taotao.qq.com/cgi-bin/photo_wall_cgi_list?uin=10001&g_tk=112308395&hostUin=qqnumber&pos=0&num=400&lastfilekey=&lasttime=0&photo_source=1&requester=1&format=json
现在照片墙还没有上限,你可以将num=400改得尽量大,接口中的uin表示你自己的QQ,g_tk需要计算得出,实际上这两个参数服务器不会校验,可以任意取,也不需要带cookies
如果没有照片返回结果是这样的
{"code":0,"data":{"next_offset":-1,"total":0,"uin":123456789,"uptime":1397711082},"message":"","subcode":0}
如果有照片,返回结果是这样的
{"code":0,"data":{"next_offset":-1,"photo_list":[{"burl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/44c23f8ad0f5d5e0c15fcf39d14267e081cd4e2091\/640","ctime":1446960924,"filekey":"44c23f8ad0f5d5e0c15fcf39d14267e081cd4e2091","murl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/44c23f8ad0f5d5e0c15fcf39d14267e081cd4e2091\/160","ourl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/44c23f8ad0f5d5e0c15fcf39d14267e081cd4e2091\/0","surl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/44c23f8ad0f5d5e0c15fcf39d14267e081cd4e2091\/100"},{"burl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/e1a706fd3d78430d5c0e3d46ae76770581cd4e2091\/640","ctime":1446960912,"filekey":"e1a706fd3d78430d5c0e3d46ae76770581cd4e2091","murl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/e1a706fd3d78430d5c0e3d46ae76770581cd4e2091\/160","ourl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/e1a706fd3d78430d5c0e3d46ae76770581cd4e2091\/0","surl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/e1a706fd3d78430d5c0e3d46ae76770581cd4e2091\/100"},{"burl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/1b3740ab132fec2567d281a6ae4ce65b81cd4e2091\/640","ctime":1446960903,"filekey":"1b3740ab132fec2567d281a6ae4ce65b81cd4e2091","murl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/1b3740ab132fec2567d281a6ae4ce65b81cd4e2091\/160","ourl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/1b3740ab132fec2567d281a6ae4ce65b81cd4e2091\/0","surl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/1b3740ab132fec2567d281a6ae4ce65b81cd4e2091\/100"},{"burl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/bf318cb2191b3a6300acf8cde68f21c681cd4e2091\/640","ctime":1412657386,"filekey":"bf318cb2191b3a6300acf8cde68f21c681cd4e2091","murl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/bf318cb2191b3a6300acf8cde68f21c681cd4e2091\/160","ourl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/bf318cb2191b3a6300acf8cde68f21c681cd4e2091\/0","surl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/bf318cb2191b3a6300acf8cde68f21c681cd4e2091\/100"},{"burl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/f3659f9cecef0cf36feea13022f4786881cd4e2091\/640","ctime":1411656582,"filekey":"f3659f9cecef0cf36feea13022f4786881cd4e2091","murl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/f3659f9cecef0cf36feea13022f4786881cd4e2091\/160","ourl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/f3659f9cecef0cf36feea13022f4786881cd4e2091\/0","surl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/f3659f9cecef0cf36feea13022f4786881cd4e2091\/100"},{"burl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/c0d3c192c33c54e978f01ec49690265481cd4e2091\/640","ctime":1411656581,"filekey":"c0d3c192c33c54e978f01ec49690265481cd4e2091","murl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/c0d3c192c33c54e978f01ec49690265481cd4e2091\/160","ourl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/c0d3c192c33c54e978f01ec49690265481cd4e2091\/0","surl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/c0d3c192c33c54e978f01ec49690265481cd4e2091\/100"},{"burl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/288d4e40e8635b229c36c99c9869c50381cd4e2091\/640","ctime":1411656541,"filekey":"288d4e40e8635b229c36c99c9869c50381cd4e2091","murl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/288d4e40e8635b229c36c99c9869c50381cd4e2091\/160","ourl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/288d4e40e8635b229c36c99c9869c50381cd4e2091\/0","surl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/288d4e40e8635b229c36c99c9869c50381cd4e2091\/100"},{"burl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/115617c351047bef607a86f68373ee3581cd4e2091\/640","ctime":1411656539,"filekey":"115617c351047bef607a86f68373ee3581cd4e2091","murl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/115617c351047bef607a86f68373ee3581cd4e2091\/160","ourl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/115617c351047bef607a86f68373ee3581cd4e2091\/0","surl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/115617c351047bef607a86f68373ee3581cd4e2091\/100"},{"burl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/b6e7e988888ace6b4d12d7ffc32f2ca781cd4e2091\/640","ctime":1397190206,"filekey":"b6e7e988888ace6b4d12d7ffc32f2ca781cd4e2091","murl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/b6e7e988888ace6b4d12d7ffc32f2ca781cd4e2091\/160","ourl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/b6e7e988888ace6b4d12d7ffc32f2ca781cd4e2091\/0","surl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/b6e7e988888ace6b4d12d7ffc32f2ca781cd4e2091\/100"},{"burl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/56bf5ea1f5096671cf365d56ab63ade781cd4e2091\/640","ctime":1397190195,"filekey":"56bf5ea1f5096671cf365d56ab63ade781cd4e2091","murl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/56bf5ea1f5096671cf365d56ab63ade781cd4e2091\/160","ourl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/56bf5ea1f5096671cf365d56ab63ade781cd4e2091\/0","surl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/56bf5ea1f5096671cf365d56ab63ade781cd4e2091\/100"},{"burl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/7acfe7c6c2e48b5b22de8e32086726d881cd4e2091\/640","ctime":1397190180,"filekey":"7acfe7c6c2e48b5b22de8e32086726d881cd4e2091","murl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/7acfe7c6c2e48b5b22de8e32086726d881cd4e2091\/160","ourl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/7acfe7c6c2e48b5b22de8e32086726d881cd4e2091\/0","surl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/7acfe7c6c2e48b5b22de8e32086726d881cd4e2091\/100"},{"burl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/82f7911a6b9a458e6ced939223964b4581cd4e2091\/640","ctime":1390318130,"filekey":"82f7911a6b9a458e6ced939223964b4581cd4e2091","murl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/82f7911a6b9a458e6ced939223964b4581cd4e2091\/160","ourl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/82f7911a6b9a458e6ced939223964b4581cd4e2091\/0","surl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/82f7911a6b9a458e6ced939223964b4581cd4e2091\/100"},{"burl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/4a2e9886148db7689dcf88a9d128f72681cd4e2091\/640","ctime":1375022218,"filekey":"4a2e9886148db7689dcf88a9d128f72681cd4e2091","murl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/4a2e9886148db7689dcf88a9d128f72681cd4e2091\/160","ourl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/4a2e9886148db7689dcf88a9d128f72681cd4e2091\/0","surl":"http:\/\/ugc.qpic.cn\/mqq_photo\/0\/4a2e9886148db7689dcf88a9d128f72681cd4e2091\/100"}],"total":13,"uin":123456789,"uptime":1446960924},"message":"","subcode":0}
我们关注total和ourl字段就可以了,total表示照片总数,ourl表示原图,其它的url是缩放过的图
老规矩,你要查的qq号做个无BOM的utf-8编码的txt放同目录下,每个QQ号占一行,最后一个QQ号需要再加一个或多个空行,文件格式根据文件头智能识别
代码如下
# -*- coding: UTF-8 -*-
import httplib2
import json
import os
import shutil
import time
import binasciidir='QQWallPhotos/'
try: os.makedirs(dir) # 建立相应的文件夹
except: shutil.rmtree(dir) # 无论文件夹是否为空都移除该文件夹 os.makedirs(dir) fp = open('qqlist.txt', 'r')
qqlist = fp.readlines() for i in range(len(qqlist)): qqlist[i] = qqlist[i][:-1]
fp.close() h = httplib2.Http(timeout=6)
for target in qqlist:url = 'http://taotao.qq.com/cgi-bin/photo_wall_cgi_list?uin=10001&g_tk=112308395&hostUin=qqnumber&pos=0&num=400&lastfilekey=&lasttime=0&photo_source=1&requester=1&format=json' if len(target) == 0 : # 防止因为出现空行删除所有照片 continuetry: os.makedirs(dir + target) # 建立相应的文件夹 except : shutil.rmtree(dir + target) # 无论文件夹是否为空都移除该文件夹 os.makedirs(dir + target) print(u'当前QQ:' + target) url=url.replace('qqnumber',target) resp = Nonecontent = Nonefor t1 in (1,6):try:resp, content = h.request(url)breakexcept:print("-----socket timout:",url)continueprint contenttry:output = json.loads(content) # json字符串转字典except:break # json字符串转字典出现异常,退出循环print output if output['code'] != 0 : # 返回结果异常,退出本次循环 continue total = output['data']['total'] # 照片墙总数,如果为0表示没有照片print totalif total != 0 :for i in range(0, len(output['data']['photo_list'])): ctime = output['data']['photo_list'][i]['ctime']filename = time.strftime("%Y%m%d%H%M%S",time.localtime(ctime))url = output['data']['photo_list'][i]['ourl']print urlresp = Nonecontent = None for t2 in (1,6):try:resp, content = h.request(url)breakexcept:print("-----socket timout:",url)continue fmt = binascii.b2a_hex(content[0:4]) # 读取前4字节转化为16进制字符串print fmt phototype = {'47494638': '.gif', 'ffd8ffe0': '.jpg', 'ffd8ffe1': '.jpg', 'ffd8ffdb': '.jpg', '89504e47': '.png'} # 智能识别文件格式 qualified_file_name = dir + target + '/' + filename + phototype[fmt] open(qualified_file_name, 'wb').write(content)if total == 0 :shutil.rmtree(dir + target)
print(u'下载完成')
更新1:增加ffd8ffdb的jpg格式
更新2:修复连接超时导致下载中断的异常
更新3:加入超时重发3次请求的机制,根据笔者监测到的情况,超时设为6秒时,超时一般出现在获取json的时候,笔者300好友数最多重发两次解决问题,总重发次数在10次以内
更新4:修复变量名命名不当以及变量未清空导致获取到上一次结果的问题
Python2.7获取QQ照片墙相关推荐
- Python2.7获取QQ空间好友头像
获取QQ空间好友头像并不复杂,通过一个网址就可以获取 获取方法: 小图 http://qlogo.store.qq.com/qzone/[QQ号]/[QQ号]/50 中图 http://qlogo.s ...
- Python2.7获取QQ好友头像
上一篇文章:http://blog.csdn.net/gsls200808/article/details/48108727获取的是空间头像,这一篇直接获取好友头像 获取QQ头像接口 大图 http: ...
- Python2.7获取QQ空间部分好友
首先需要安装curl工具,然后复制curl 参考http://blog.csdn.net/gsls200808/article/details/46933307 浏览器打开http://user.qz ...
- Python2.7获取QQ空间全部好友
通过Wireshark抓包,QQ空间有个获取全部好友的接口 URL地址 http://m.qzone.com/friend/mfriend_list?g_tk=1399550749&res_u ...
- Python3.6获取QQ空间全部好友列表
首先要处理的是gtk算法:从上次分析以来代码并没有变 登录QQ空间后搜索gtk字符串,在三个js中出现了 operation.50303.js gdtlib.20160810.js index.js ...
- 在线python爬取好友qq空间_Python3.6获取QQ空间全部好友列表
首先要处理的是gtk算法:从上次分析以来代码并没有变 登录QQ空间后搜索gtk字符串,在三个js中出现了 /* |xGv00|e5808eb94a2bdffe3aae60cd22c5efe2 */ d ...
- 使用腾讯开发平台获取QQ用户数据资料
<今天是七夕:祝大家七夕嗨皮,前可么么哒,后可啪啪啪> Tips:本篇博客将教你如何使用腾讯开发平台获取QQ用户资料 ----------------------------------- ...
- html获取qq头像代码,jQuery在线获取QQ名称和头像
正文 昨天群里有人问到dux主题的评论处输入QQ号直接获取名称和头像是怎么实现的,我看了一下dux主题,发现并没有集成这个功能,倒是emlog的dux主题内置了这个功能,本来想移植过来wordpres ...
- android qq登录 获取用户信息吗,免登录 只需要一个QQ号就能获取QQ头像和QQ昵称 获取QQ用户信息API...
[PHP] 纯文本查看 复制代码<?php // header header("Content-Type:application/json"); error_reportin ...
最新文章
- Java---replace与replaceAll的区别
- Py之PIL:不一样的PS之利用PIL库的img.paste方法实现合成刘若英导演电影《后来的我们》海报设计
- Vbox配置仅主机模式
- 2016年6月TIOBE编程语言排行榜:涨幅最大的名字很长
- mysql主从授权_MySQL主从复制(10)读写分离授权多种方案
- WINVER和_WIN32_IE等宏的含义
- B2C和B2B之间有多大差距
- Leetcode--714. 买卖股票的最佳时间含手续费
- OCR技术系列实践:银行卡、身份证、门牌号、护照、车牌、印刷体汉字识别
- Replication的犄角旮旯(二)--寻找订阅端丢失的记录
- 如何建立个人创业的基石
- 理论知识内容有_育婴师培训课程包含哪些内容?
- linux 安装arial字体,在CentOS中安装arial字体
- Java获取四分位数
- 没有互联网,如何本地获取到LoRaWAN的终端数据?
- 软件 -- 如何解除 tv15商业版的限制
- LeetCode刷题——剑指offer深度优先搜索题目汇总
- php 接入google 验证用户登录
- 刷屏!日本内政部向国民宣传5G的短视频:未来将是这样!
- php中文的正则表达式_php 正则表达式匹配中文汉字