实战:带你用Python爬取抖音app视频
http://v1-dy.ixigua.com/;http://v3-dy.ixigua.com/;http://v9-dy.ixigua.com/
import requests
# 文件路径
path = 'D:/video/'
num = 1788
def response(flow):
global num
# 经测试发现视频url前缀主要是3个
target_urls = ['http://v1-dy.ixigua.com/', 'http://v9-dy.ixigua.com/',
'http://v3-dy.ixigua.com/']
for url in target_urls:
# 过滤掉不需要的url
if flow.request.url.startswith(url):
# 设置视频名
filename = path + str(num) + '.mp4'
# 使用request获取视频url的内容
# stream=True作用是推迟下载响应体直到访问Response.content属性
res = requests.get(flow.request.url, stream=True)
# 将视频写入文件夹
with open(filename, 'ab') as f:
f.write(res.content)
f.flush()
print(filename + '下载完成')
num += 1
{
"platformName": "Android",
"deviceName": "Mi_Note_3",
"appPackage": "com.ss.android.ugc.aweme",
"appActivity": ".main.MainActivity"
}
from appium import webdriver
from time import sleep
class Action():
def __init__(self):
# 初始化配置,设置Desired Capabilities参数
self.desired_caps = {
"platformName": "Android",
"deviceName": "Mi_Note_3",
"appPackage": "com.ss.android.ugc.aweme",
"appActivity": ".main.MainActivity"
}
# 指定Appium Server
self.server = 'http://localhost:4723/wd/hub'
# 新建一个Session
self.driver = webdriver.Remote(self.server, self.desired_caps)
# 设置滑动初始坐标和滑动距离
self.start_x = 500
self.start_y = 1500
self.distance = 1300
def comments(self):
sleep(2)
# app开启之后点击一次屏幕,确保页面的展示
self.driver.tap([(500, 1200)], 500)
def scroll(self):
# 无限滑动
while True:
# 模拟滑动
self.driver.swipe(self.start_x, self.start_y, self.start_x,
self.start_y-self.distance)
# 设置延时等待
sleep(2)
def main(self):
self.comments()
self.scroll()
if __name__ == '__main__':
action = Action()
action.main()
原文链接:https://urlify.cn/ANzAre
文章转载:Python编程学习圈
(版权归原作者所有,侵删)
有收获,点个在看
评论