使用python实现qq空间自动点赞功能。

需自行安装库并配置环境。

我想实现的是每6个小时就自动更新一次cookie。这也是和网上其他版本相比具有的优点。不用手动输入cookie。更加自动。(不负责任的说,这个功能没有测试过。)

程序运行方法:将代码存为.py文件,运行即可。

输入QQ密码的时候采用了linux登录的方式——没有回显。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

from selenium import webdriver

from selenium.webdriver.chrome.options import Options

import time

import requests

import demjson

import re

import datetime

import getpass

 

 

qq = ''

pwd = ''

 

 

def print_time():

 print(datetime.datetime.now(), end=' ')

 

 

def get_gtk(p_skey):

 hash=5381

 for i in p_skey:

  hash += (hash << 5)+ord(i)

 

 print_time()

 print('生成gtk')

 return hash & 0x7fffffff

 

 

def change_cookie(cookie):

 s = ''

 for c in cookie:

  s = s + c['name'] + '=' + c['value'] + '; '

 

 return s

 

 

def check_time():

 now = datetime.datetime.now()

 hour = str(now)[11:13]

 minute = str(now)[14:16]

 second = str(now)[17:19]

 

 if 0 == int(hour) % 6 and minute == '00' and int(second) < 30:

  return True

 else:

  return False

 

 

def get_cookie():

 chrome_options = Options()

 chrome_options.add_argument('--headless')

 driver = webdriver.Chrome(chrome_options=chrome_options)

 

 driver.get('https://qzone.qq.com/')

 

 driver.switch_to.frame('login_frame')

 

 driver.find_element_by_id('switcher_plogin').click()

 driver.find_element_by_id('u').clear()

 driver.find_element_by_id('u').send_keys(qq)

 driver.find_element_by_id('p').clear()

 driver.find_element_by_id('p').send_keys(pwd)

 driver.find_element_by_id('login_button').click()

 

 time.sleep(1)

 

 driver.find_element_by_id('QZ_Body').click()

 

 cookie = driver.get_cookies()

 

 # print(cookie)

 

 driver.close()

 driver.quit()

 

 print_time()

 print('提取cookie')

 

 return cookie

 

 

def get_args():

 cookie = get_cookie()

 

 for c in cookie:

  if c['name'] == 'p_skey':

   p_skey = c['value']

   break

 

 cookie = change_cookie(cookie)

 

 # print(p_skey)

 

 gtk = get_gtk(p_skey)

 

 return cookie, gtk

 

 

def do_like(d, gtk, headers):

 url = 'https://user.qzone.qq.com/proxy/domain/w.qzone.qq.com/cgi-bin/likes/internal_dolike_app?g_tk=' + str(gtk)

 

 body = {

  'qzreferrer': 'http://user.qzone.qq.com/' + qq,

  'opuin': qq,

  'from': 1,

  'active': 0,

  'fupdate': 1

 }

 

 try:

  html = d['html']

 

  # print(html)

  # unikey = re.search(r'data-unikey=\"http:[^"]*\"', html).group(0)

  # curkey = re.search(r'data-curkey=\"http:[^"]*\"', html).group(0)

  # print(unikey, curkey)

 

  temp = re.search('data-unikey="(http[^"]*)"[^d]*data-curkey="([^"]*)"[^d]*data-clicklog=("like")[^h]*href="javascript:;" rel="external nofollow" rel="external nofollow" ', html);

 

  if temp is None:

   return

 

  unikey = temp.group(1);

  curkey = temp.group(2);

 

  # print(unikey, curkey)

 

  body['unikey'] = unikey

  body['curkey'] = curkey

  body['appid'] = d['appid']

  body['typeid'] = d['typeid']

  body['fid'] = d['key']

 

  r = requests.post(url, data=body, headers=headers)

 

  if 200 == r.status_code:

   print_time()

   print('给 ' + d['nickname'] + ' 点赞')

 

 except:

  return

 

 

def get_content(headers, gtk):

 try:

  r = requests.get('http://ic2.s8.qzone.qq.com/cgi-bin/feeds/feeds3_html_more?uin=0924761163&scope=0&view=1&daylist=&uinlist=&gid=&flag=1&filter=all&applist=all&refresh=0&aisortEndTime=0&aisortOffset=0&getAisort=0&aisortBeginTime=0&pagenum=1&externparam=offset%3D6%26total%3D97%26basetime%3D1470323193%26feedsource%3D0&firstGetGroup=0&icServerTime=0&mixnocache=0&scene=0&begintime=0&count=10&dayspac=0&sidomain=cnc.qzonestyle.gtimg.cn&useutf8=1&outputhtmlfeed=1&getob=1&g_tk=' + str(gtk), headers=headers)

 

  r = r.text[10:-2]

 

  r = demjson.decode(r)

 

  data = r['data']['data']

 

  print_time()

  print('获取了 ' + str(len(data)) + ' 条说说')

 

  return data

 except:

  return []

 

 

def main():

 

 print_time()

 print('程序运行...')

 

 global qq

 global pwd

 

 qq = input('QQ:')

 pwd = getpass.getpass('Password:')

 

 headers = {

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

 }

 

 cookie, gtk = get_args()

 headers['Cookie'] = cookie

 

 while True:

  time.sleep(1)

 

  if check_time():

   cookie, gtk = get_args()

   headers['Cookie'] = cookie

 

   print_time()

   print('更新了 cookie 和 gtk')

 

  data = get_content(headers, gtk)

 

  for d in data:

   do_like(d, gtk, headers)

 

 

if __name__ == '__main__':

 main()

这个程序在本地跑没有问题,但是我希望它能在我的腾讯云服务器上一直运行。

我在辽宁,服务器在北京,导致登录qq空间时会有滑动验证码。

于是我按照网上的教程,结合qq空间滑动验证码的实际情况,实现了qq空间滑动验证码的破解。

值得一提的是,目前成功率是100%。

有的时候不能完全重合,但还是会成功。

具体思路我就不贴出来了,感兴趣的朋友可以私信我。

下面是整合了破解滑动验证码部分的代码。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

from selenium import webdriver

from selenium.webdriver.chrome.options import Options

from selenium.webdriver.common.action_chains import ActionChains

from PIL import Image

from io import BytesIO

import time

import requests

import demjson

import re

import datetime

import getpass

 

 

qq = ''

pwd = ''

 

 

def print_time():

 print(datetime.datetime.now(), end=' ')

 

 

def get_gtk(p_skey):

 hash=5381

 for i in p_skey:

  hash += (hash << 5)+ord(i)

 

 print_time()

 print('生成gtk')

 return hash & 0x7fffffff

 

 

def change_cookie(cookie):

 s = ''

 for c in cookie:

  s = s + c['name'] + '=' + c['value'] + '; '

 

 return s

 

 

def check_time():

 now = datetime.datetime.now()

 hour = str(now)[11:13]

 minute = str(now)[14:16]

 second = str(now)[17:19]

 

 if 0 == int(hour) % 6 and minute == '00' and int(second) < 30:

  return True

 else:

  return False

 

 

def get_image_difference(back_img, full_img):

 width, height = full_img.size

 

 for w in range(0, width):

  for h in range(0, height):

   back_pixel = back_img.getpixel((w, h))

   full_pixel = full_img.getpixel((w, h))

 

   if back_pixel != full_pixel and w > 340 and h > 10 and abs(back_pixel[0]-full_pixel[0])>50 and abs(back_pixel[1]-full_pixel[1])>50 and abs(back_pixel[2]-full_pixel[2])>50:

    return True, w

 

 return False, -1

 

 

def get_cookie():

 chrome_options = Options()

 chrome_options.add_argument('--headless')

 driver = webdriver.Chrome(chrome_options=chrome_options)

 

 driver.get('https://qzone.qq.com/')

 

 driver.switch_to.frame('login_frame')

 

 driver.find_element_by_id('switcher_plogin').click()

 driver.find_element_by_id('u').clear()

 driver.find_element_by_id('u').send_keys(qq)

 driver.find_element_by_id('p').clear()

 driver.find_element_by_id('p').send_keys(pwd)

 driver.find_element_by_id('login_button').click()

 

 time.sleep(3)

 frame = driver.find_element_by_xpath('//*[@id="newVcodeIframe"]/iframe')

 driver.switch_to.frame(frame)

 

 #

 back_url = driver.find_element_by_id('slideBkg').get_attribute('src')

 full_url = back_url.replace('hycdn_1', 'hycdn_0')

 

 r = requests.get(back_url)

 file = BytesIO(r.content)

 back_img = Image.open(file)

 

 r.status_code = 500

 while 200 != r.status_code:

  r = requests.get(full_url)

 

 file = BytesIO(r.content)

 full_img = Image.open(file)

 

 r, w = get_image_difference(back_img, full_img)

 if r is False:

  return

 

 # print(w)

 # 280 * 158

 # 680 * 390

 # 55 * 55

 # 136 * 136

 # 214

 

 slide = driver.find_element_by_id('tcaptcha_drag_thumb')

 ActionChains(driver).click_and_hold(slide).perform()

 ActionChains(driver).move_by_offset(xoffset=w / 680 * 250, yoffset=0).perform()

 ActionChains(driver).release(slide).perform()

 

 # print(back_img.size)

 # print(cut_img.size)

 # print(full_img.size)

 

 time.sleep(2)

 

 driver.find_element_by_id('QZ_Body').click()

 

 cookie = driver.get_cookies()

 

 # print(cookie)

 

 driver.close()

 driver.quit()

 

 print_time()

 print('提取cookie')

 

 return cookie

 

 

def get_args():

 cookie = get_cookie()

 

 for c in cookie:

  if c['name'] == 'p_skey':

   p_skey = c['value']

   break

 

 cookie = change_cookie(cookie)

 

 # print(p_skey)

 

 gtk = get_gtk(p_skey)

 

 return cookie, gtk

 

 

def do_like(d, gtk, headers):

 url = 'https://user.qzone.qq.com/proxy/domain/w.qzone.qq.com/cgi-bin/likes/internal_dolike_app?g_tk=' + str(gtk)

 

 body = {

  'qzreferrer': 'http://user.qzone.qq.com/' + qq,

  'opuin': qq,

  'from': 1,

  'active': 0,

  'fupdate': 1

 }

 

 try:

  html = d['html']

 

  # print(html)

  # unikey = re.search(r'data-unikey=\"http:[^"]*\"', html).group(0)

  # curkey = re.search(r'data-curkey=\"http:[^"]*\"', html).group(0)

  # print(unikey, curkey)

 

  temp = re.search('data-unikey="(http[^"]*)"[^d]*data-curkey="([^"]*)"[^d]*data-clicklog=("like")[^h]*href="javascript:;" rel="external nofollow" rel="external nofollow" ', html);

 

  if temp is None:

   return

 

  unikey = temp.group(1);

  curkey = temp.group(2);

 

  # print(unikey, curkey)

 

  body['unikey'] = unikey

  body['curkey'] = curkey

  body['appid'] = d['appid']

  body['typeid'] = d['typeid']

  body['fid'] = d['key']

 

  r = requests.post(url, data=body, headers=headers)

 

  if 200 == r.status_code:

   print_time()

   print('给 ' + d['nickname'] + ' 点赞')

 

 except:

  return

 

 

def get_content(headers, gtk):

 

 try:

  r = requests.get('http://ic2.s8.qzone.qq.com/cgi-bin/feeds/feeds3_html_more?uin=0924761163&scope=0&view=1&daylist=&uinlist=&gid=&flag=1&filter=all&applist=all&refresh=0&aisortEndTime=0&aisortOffset=0&getAisort=0&aisortBeginTime=0&pagenum=1&externparam=offset%3D6%26total%3D97%26basetime%3D1470323193%26feedsource%3D0&firstGetGroup=0&icServerTime=0&mixnocache=0&scene=0&begintime=0&count=10&dayspac=0&sidomain=cnc.qzonestyle.gtimg.cn&useutf8=1&outputhtmlfeed=1&getob=1&g_tk=' + str(gtk), headers=headers)

 

  r = r.text[10:-2]

 

  r = demjson.decode(r)

 

  data = r['data']['data']

 

  print_time()

  print('获取了 ' + str(len(data)) + ' 条说说')

 

  return data

 except:

  return []

 

 

def main():

 

 print_time()

 print('程序运行...')

 

 global qq

 global pwd

 

 qq = input('QQ:')

 pwd = getpass.getpass('Password:')

 

 headers = {

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

 }

 

 cookie, gtk = get_args()

 headers['Cookie'] = cookie

 

 while True:

  time.sleep(1)

 

  if check_time():

   cookie, gtk = get_args()

   headers['Cookie'] = cookie

 

   print_time()

   print('更新了 cookie 和 gtk')

 

  data = get_content(headers, gtk)

 

  for d in data:

   do_like(d, gtk, headers)

 

 

if __name__ == '__main__':

 main()

上面两份代码整体思路没问题,但是偶尔会有一些小bug。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

python实现QQ空间自动点赞功能相关推荐

  1. 基于selenium的QQ空间自动点赞功能(2020年7月版)

    准备工作 简介: selenium是一个基于java开发的自动化浏览器处理器,它更像是浏览器驱动的代理. 配置: 它本身没有配置浏览器,因此需要配合本机上面安装的浏览器驱动一同使用.例如:Firefo ...

  2. 24行代码简单实现qq空间自动点赞

    什么是Auto.js? Auto.js是基于JavaScript语言运行在Android平台上的工具.它依赖于无障碍服务. 它可以做什么? 解放双手,让手机自动打游戏.自动签到.自动领红包等等等等 它 ...

  3. PHP爬虫之QQ空间自动点赞--更换cookie版

    QQ空间自动点赞网上一搜一大把,但是关于php的还是停留在用以前的3Gqq登陆方式获取sid之后再点赞的.而现在貌似3Gqq没法用了, 网上也没有关于最新的.实现QQ空间自动点赞已经很久了,一直没有发 ...

  4. QQ空间自动点赞脚本

    先放上代码: 在浏览器开发者工具里面的控制台(console)里面粘贴这段代码,然后回车就可以了,前提是qq空间的页面要一直开着,在个人中心可以运行. var clicklog = function( ...

  5. Python3爬虫实践——QQ空间自动点赞程序(下)

    (发完上一篇博客之后,观察了一个星期发现阅读量迟迟突破不了50大关,蓝瘦香菇+心疼自己T.T,于是果然又找到了各种拖延的理由,刚才登博客的时候突然发现有人评论期待我的下篇,立马精神振奋!开始敲字.) ...

  6. JS实例操作QQ空间自动点赞方法

    做开法的小伙伴都知道我们在查找网络资源时,通常会通过 使用谷歌浏览器的 F12 对页面元素进行操作,且可以查看一些网络资源,当然火狐浏览器也有这种功能,不是IE就好了. 打开QQ空间 按下 F12 , ...

  7. [转] JS实例操作QQ空间自动点赞方法

    做开法的小伙伴都知道我们在查找网络资源时,通常会通过 使用谷歌浏览器的 F12 对页面元素进行操作,且可以查看一些网络资源,当然火狐浏览器也有这种功能,不是IE就好了. 打开QQ空间 按下 F12 , ...

  8. QQ空间自动点赞js脚本

    这是很久前写的脚本了,在浏览器打开QQ空间,并在控制台输入代码就可 时间间隔最好开大点,不然容易被暂时冻结账号 1 function autoLike() 2 { 3 var list=documen ...

  9. 利用浏览器JS代码实现QQ空间自动点赞

    我不喜欢我的时间用来看说说,因为我的朋友和同学总是在说话,要求关注点赞.虽然我不喜欢看空间,但是有时候也确实有这个需求.而且有时候碍于一些原因不得不去帮别人点赞,但是自己又没时间或者不想去翻空间的时候 ...

  10. C#源码QQ空间自动点赞神器,无需密码直接点头像登录,可加自动功能评论转发等。

    使用C#开发的:最新版V5.7下载https://pan.baidu.com/s/1ZOG2KLV8z0pXNXjCRfMMhw 可以直接看见页面操作结果. 功能: 1.朋友发表说说,第一时间点赞. ...

最新文章

  1. 构造方法与setXxx方法
  2. 【Android 安全】使用 360 加固宝加固应用 ( 购买高级加固服务 | 设置资源加固 | 设置 SO 文件保护配置 | 设置 SO 防盗用文件配置 | 反编译验证加固效果 )
  3. 排序算法----快速排序(数组形式)
  4. 开发效率提升15倍!批流融合实时平台在好未来的应用实践
  5. action script3.0殿堂之路_【日本乐坛传奇】松任谷由实是谁?新音乐女王的登基之路!...
  6. Vim引申以及Linux下彩色进度条实现
  7. springmvc源码阅读3--dispatcherServlet reqeust的执行流程
  8. eclipse Android开发——布局查看
  9. 巧谈自动化测试面试技巧,面试中会问到的技术点讲解!
  10. java取当前北京时间_用Java取指定时区的时间 北京时间,纽约时间,班加罗尔时间...
  11. iPhone查询商品历史价格详细教程
  12. SP10108 BALLOT - Distributing Ballot Boxes(二分查找)
  13. C语言打印图形小妙招
  14. 关于本人树莓派捣鼓过程中的一些记录
  15. 3dsmax2014安装激活之 “软件许可证检出失败 错误20”或者显示错误5。
  16. filco蓝牙不好用_蓝牙党+精简布局键位的选择:Filco Minila Air青轴两个月使用体验...
  17. Android个人信息页面
  18. 使用cocoscreator接入google AdSence广告
  19. JEPF软件快速开发平台学习心得之请假单功能的完成(一)
  20. Nirvana Chain 为应用而生技术交流酒会在成都成功举办

热门文章

  1. java+swing+mysql小型超市管理系统
  2. ArcGIS 10 SP5 (Desktop, Engine, Server)中文版 补丁
  3. c51计数器代码汇编语言,51单片机6位计数器汇编程序
  4. Verilog——计数器
  5. 软件是指示计算机运行所需的程序,计算机文化基础知识点
  6. Android office教程,Excel办公软件Office教程app
  7. Xen虚拟化环境安装和常用命令
  8. (云安全)拖库-洗库-撞库
  9. 系统分析师(4)-系统分析师考试大纲
  10. python辅助开发工具_Python开发工具:WingPro 7