Python-demo(抖音)

时间:2019-08-28
本文章向大家介绍Python-demo(抖音),主要包括Python-demo(抖音)使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
 1 # -*- coding:utf-8 -*-
 2 
 3 
 4 from mitmproxy import ctx
 5 import json
 6 import requests
 7 import time
 8 import os
 9 path = "抖音视频/"
10 initUrl = ["http://v1-dy.bytecdn.cn","http://v2-dy.bytecdn.cn","http://v3-dy.bytecdn.cn","http://v4-dy.bytecdn.cn","http://v5-dy.bytecdn.cn","http://v6-dy.bytecdn.cn"]
11 
12 num = 0
13 def response(flow):
14     global num
15     for url in initUrl:
16         # 过滤掉不需要的url
17         if flow.request.url.startswith(url):
18             print(flow.request.url)
19             # 设置视频名
20             filename = path + str(num) + '.mp4'
21             print(filename)
22             # 使用request获取视频url的内容
23             # stream=True作用是推迟下载响应体直到访问Response.content属性
24 
25             res = requests.get(flow.request.url, stream=True)
26             # 将视频写入文件夹
27             with open(filename, 'ab') as f:
28                 f.write(res.content)
29                 f.flush()
30                 print(filename + '下载完成')
31             num += 1
 1 #   _*_ coding:utf-8 _*_
 2 
 3 import os
 4 
 5 #from PIL import Image
 6 
 7 import subprocess
 8 
 9 import time
10 
11 __author__ = 'admin'
12 
13 # order='adb devices' #获取连接设备
14 # pi= subprocess.Popen(order,shell=True,stdout=subprocess.PIPE)
15 # print(pi.stdout.read())#打印结果
16 def mobile_in(code):
17     #   开启电源键
18     # os.popen('adb shell input keyevent 26')
19     time.sleep(1)
20     #   滑动屏幕进入输入密码界面
21     os.popen('adb shell input swipe 539 1868 539 1600')
22     time.sleep(1)
23     for i in range(len(code)):
24         if code[i] == '0':
25             #   密码盘上的“0”
26             os.popen('adb shell input swipe 480 1440 600 1550')
27             time.sleep(1)
28         elif code[i] == '1':
29             #   密码盘上的“1”
30             os.popen('adb shell input swipe 200 740 320 860')
31             time.sleep(1)
32         elif code[i] == '2':
33             #   密码盘上的“2”
34             os.popen('adb shell input swipe 480 740 600 860')
35         elif code[i] == '3':
36             #   密码盘上的“3”
37             os.popen('adb shell input swipe 760 740 880 860')
38         elif code[i] == '4':
39             #   密码盘上的“4”
40             os.popen('adb shell input swipe 200 990 320 1110')
41         elif code[i] == '5':
42             #   密码盘上的“5”
43             os.popen('adb shell input swipe 480 990 600 1110')
44         elif code[i] == '6':
45             #   密码盘上的“6”
46             os.popen('adb shell input swipe 760 990 880 1110')
47         elif code[i] == '7':
48             #   密码盘上的“7”
49             os.popen('adb shell input swipe 200 1240 320 1360')
50         elif code[i] == '8':
51             #   密码盘上的“8”
52             os.popen('adb shell input swipe 480 1240 600 1360')
53         elif code[i] == '9':
54             #   密码盘上的“9”
55             os.popen('adb shell input swipe 760 1240 880 1360')
56         time.sleep(1)
57 
58 
59 code = list('1115')
60 #手机解锁
61 #mobile_in(code)
62 
63 # startapp = "adb shell am start -n com.ss.android.ugc.aweme/.main.MainActivity"
64 
65 def loop(times):
66     for i in range(times):
67         os.popen('adb shell input swipe 539 800 539 400')
68         time.sleep(2)
69 
70 if __name__ == "__main__":
71     # os.popen(startapp)
72     time.sleep(5)
73     loop(30)

原文地址:https://www.cnblogs.com/Chen-MJ/p/11423175.html