python分析qq好友_Python2.7获取QQ空间部分好友

首先需要安装curl工具,然后复制curl

参考http://blog..net/gsls200808/article/details/46933307

浏览器打开http://user.qzone.qq.com/[QQ号码]/myhome/friends,复制friend_ship_manager.cgi为curl

获取的是我在意谁和谁在意我的json列表,QQ空间对我在意谁的好友数目限制是200,谁在意我的好友数目限制是200,代码把两个列表全部获取了,但是通过这个方法有个缺陷,当好友数大于200时,无法获取完整的好友列表

代码如下

# -*- coding: UTF-8 -*-

import os

import shlex

import subprocess

import json

# 添加curl的环境变量

os.putenv('PATH', 'D:\\curl-7.33.0-win64-nossl\\;' + os.getenv('PATH'))

# 浏览器打开http://user.qzone.qq.com/[QQ号码]/myhome/friends,复制friend_ship_manager.cgi为curl

# 我在意谁do=1,谁在意我do=2

origin_friend = 'friend_ship_manager.cgi'

origin_friend = origin_friend.replace('--compressed ', '')

curl = origin_friend

args = shlex.split(curl)

result = subprocess.check_output(args).decode('utf-8')

jsonstr = result[result.find('(') + 1: result.find(')', -1) - 1] # json字符串,去除不标准的json数据

output = json.loads(jsonstr) # 最终json数据

items_list=output['data']['items_list']

qqlist = set()

for item in items_list:

qqlist.add(item['uin'])

# 获取谁在意我

origin_friend_whocare = origin_friend

curl = origin_friend_whocare.replace('do=1', 'do=2')

args = shlex.split(curl)

result = subprocess.check_output(args).decode('utf-8')

jsonstr = result[result.find('(') + 1: result.find(')', -1) - 1] # json字符串,去除不标准的json数据

output = json.loads(jsonstr) # 最终json数据

items_list=output['data']['items_list']

for item in items_list:

qqlist.add(item['uin'])

# 打印信息并输出到文件

print '获取QQ号个数'+str(len(qqlist))

filename='qqlist.txt'

fileobj = open(filename, 'w')

result = [str(qq) + '\n' for qq in sorted(qqlist)]

fileobj.writelines(result)

fileobj.flush()

fileobj.close()

print '写入完成'

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值