appium 爬取抖音
1.MongoDB.py
import pymongo
from pymongo.collection import Collection
client = pymongo.MongoClient(host='192.168.54.41',port=27017)
db = client['douyin']
def send_task():
with open('douyin_hot_id.txt','r') as f:
f_read = f.readlines()
for i in f_read:
task_info = {}
task_info['share_id'] = i.replace('\n','')
task_info['task_type'] = 'share_id'
print('当前保存的task为%s:'%task_info)
save_task(task_info)
def save_task(task): # 保存数据到mongodb中
task_collections = Collection(db,'douyin_task')
task_collections.update({'share_id':task['share_id']},task,True)
def get_task(task_type):
task_collections = Collection(db,'douyin_task')
task = task_collections.find_one_and_delete({'task_type':task_type})
return task
def delete_task(task):
pass
def save_data(item):
data_collections = Collection(db,'douyin_data')
data_collections.insert(item)
2.decode.py
import json
try:
from douyin.handle_mongo import save_task
except:
from handle_mongo import save_task
def response(flow):
if 'aweme/v1/user/follower/list/' in flow.request.url:
for user in json.loads(flow.response.text)['followers']:
douyin_info = {}
douyin_info['share_id'] = user['uid']
douyin_info['douyin_id'] = user['short_id']
save_task(douyin_info)
3.douyin.py
import time
from selenium.webdriver.support.ui import WebDriverWait
from appium import webdriver
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['deviceName'] = 'TGIRPJOBFUZ9IJSW'
desired_caps['platformVersion'] = '6.0'
desired_caps['appPackage'] = 'com.ss.android.ugc.aweme'
desired_caps['appActivity'] = 'com.ss.android.ugc.aweme.splash.SplashActivity'
desired_caps['noReset'] = True
desired_caps['unicodeKeyboard'] = True
desired_caps['resetKeyboard'] = True
driver = webdriver.Remote('http://192.168.54.56:4723/wd/hub', desired_caps)
def get_size(driver):
x = driver.get_window_size()['width']
y = driver.get_window_size()['height']
return (x, y)
def handle_douyin(driver):
# 处理权限
try:
while WebDriverWait(driver, 5).until(lambda x: x.find_element_by_xpath(
"//android.widget.TextView[@resource-id='android:id/le_bottomsheet_default_title']")):
driver.find_element_by_xpath(
"//android.widget.Button[@resource-id='com.android.packageinstaller:id/permission_allow_button']").click()
except:
pass
try:
# 点击搜索
print('点击搜索')
if WebDriverWait(driver, 3).until(lambda x: x.find_element_by_xpath(
"//android.widget.ImageView[@resource-id='com.ss.android.ugc.aweme:id/ab_']")):
driver.find_element_by_xpath(
"//android.widget.ImageView[@resource-id='com.ss.android.ugc.aweme:id/ab_']").click()
except:
# [26,76][115,165]
driver.tap([(26, 76), (115, 165)], 500) # 控件所在的位置 不适用xpath 500是表示点击500毫秒
# 定位搜索框
if WebDriverWait(driver, 3).until(lambda x: x.find_element_by_xpath(
"//android.widget.EditText[@resource-id='com.ss.android.ugc.aweme:id/a4p']")):
# 获取douyin_id进行搜索
driver.find_element_by_xpath(
"//android.widget.EditText[@resource-id='com.ss.android.ugc.aweme:id/a4p']").send_keys('lwnx1208')
while driver.find_element_by_xpath(
"//android.widget.EditText[@resource-id='com.ss.android.ugc.aweme:id/a4p']").text != 'lwnx1208':
driver.find_element_by_xpath(
"//android.widget.EditText[@resource-id='com.ss.android.ugc.aweme:id/a4p']").send_keys('lwnx1208')
time.sleep(0.1)
# 点击搜索
driver.find_element_by_xpath("//android.widget.TextView[@resource-id='com.ss.android.ugc.aweme:id/a4r']").click()
# 点击用户标签
if WebDriverWait(driver, 3).until(lambda x: x.find_element_by_xpath("//android.widget.TextView[@text='用户']")):
driver.find_element_by_xpath("//android.widget.TextView[@text='用户']").click()
# 点击头像
if WebDriverWait(driver, 3).until(lambda x: x.find_element_by_xpath(
"//android.support.v7.widget.RecyclerView[@resource-id='com.ss.android.ugc.aweme:id/kh']/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.ImageView[1]")):
driver.find_element_by_xpath(
"//android.support.v7.widget.RecyclerView[@resource-id='com.ss.android.ugc.aweme:id/kh']/android.widget.RelativeLayout[1]/android.widget.RelativeLayout[1]/android.widget.ImageView[1]").click()
# 点击粉丝按钮
if WebDriverWait(driver, 3).until(lambda x: x.find_element_by_xpath(
"//android.widget.TextView[@resource-id='com.ss.android.ugc.aweme:id/a6a']")):
driver.find_element_by_xpath(
"//android.widget.TextView[@resource-id='com.ss.android.ugc.aweme:id/a6a']").click()
l = get_size(driver)
x1 = int(l[0] * 0.5)
y1 = int(l[1] * 0.75)
y2 = int(l[1] * 0.25)
while True:
if '没有更多了' in driver.page_source:
break
driver.swipe(x1, y1, x1, y2)
time.sleep(0.5)
if __name__ == '__main__':
handle_douyin(driver)
appium 爬取抖音的更多相关文章
- 使用python爬虫,批量爬取抖音app视频(requests+Fiddler+appium)
抖音很火,楼主使用python随机爬取抖音视频,并且无水印下载,人家都说天下没有爬不到的数据,so,楼主决定试试水,纯属技术爱好,分享给大家.. 1.楼主首先使用Fiddler4来抓取手机抖音app这 ...
- from appium import webdriver 使用python爬虫,批量爬取抖音app视频(requests+Fiddler+appium)
使用python爬虫,批量爬取抖音app视频(requests+Fiddler+appium) - 北平吴彦祖 - 博客园 https://www.cnblogs.com/stevenshushu/p ...
- 教你用python爬取抖音app视频
记录一下如何用python爬取app数据,本文以爬取抖音视频app为例. 编程工具:pycharm app抓包工具:mitmproxy app自动化工具:appium 运行环境:windows10 思 ...
- python爬取抖音APP视频教程
本文讲述爬取抖音APP视频数据(本文未完,后面还有很多地方优化总结) 公众号回复:抖音 即可获取源码 1.APP抓包教程,需要用到fiddler fiddler配置和使用查看>>王者荣耀盒 ...
- Python爬虫---爬取抖音短视频
目录 前言 抖音爬虫制作 选定网页 分析网页 提取id构造网址 拼接数据包链接 获取视频地址 下载视频 全部代码 实现结果 待解决的问题 前言 最近一直想要写一个抖音爬虫来批量下载抖音的短视频,但是经 ...
- Python爬取抖音视频
最近在研究Python爬虫,顺便爬了一下抖音上的视频,找到了哥们喜欢的小姐姐居多,咱们给他爬下来吧. 最终爬取结果 好了废话补多说了,上代码! #https://www.iesdouyin.com/a ...
- python+fiddler 抓取抖音数据包并下载抖音视频
这个我们要下载视频,那么肯定首先去找抖音视频的url地址,那么这个地址肯定在json格式的数据包中,所以我们就去专门查看json格式数据包 这个怎么找我就不用了,直接看结果吧 你找json包,可以选大 ...
- 一篇文章教会你用Python抓取抖音app热点数据
今天给大家分享一篇简单的安卓app数据分析及抓取方法.以抖音为例,我们想要抓取抖音的热点榜数据. 要知道,这个数据是没有网页版的,只能从手机端下手. 首先我们要安装charles抓包APP数据,它是一 ...
- python爬虫24 | 搞事情了,用 Appium 爬取你的微信朋友圈。
昨天小帅b看到一些事情不顺眼 有人偷换概念 忍不住就写了一篇反讽 996 的 看不下去了,我支持996,年轻人就该996! 没想到有些人看不懂 这就算了 还来骂我 早些时候关注我的小伙伴应该知道我第一 ...
随机推荐
- css3/sass 样式记录
css3 width: calc(50% - 10px) sass 1.奇偶行 .classNameA { background:red; &:nth-child(even) { backgr ...
- 对mglearn库的理解(转)
https://blog.csdn.net/az9996/article/details/86490496
- Web页面精确定位
Web端页面定位相关 一.获取宽高相关属性 scrollHeight:获取对象的滚动高度: scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离: scrollTop: ...
- Algorithm: CRT、EX-CRT & Lucas、Ex-Lucas
中国剩余定理 中国剩余定理,Chinese Remainder Theorem,又称孙子定理,给出了一元线性同余方程组的有解判定条件,并用构造法给出了通解的具体形式. \[ \begin{aligne ...
- EntityFrameworkCore 学习笔记之示例一
直接贴代码了: 1. Program.cs using Microsoft.EntityFrameworkCore; using System; using System.Threading.Task ...
- War 包部署
Springboot 进行war包部署,以及踩坑历险!!! https://www.jianshu.com/p/4c2f27809571 Springboot2项目配置(热部署+war+外部tomca ...
- mysql error 1364 Field doesn't have a default values
https://stackoverflow.com/questions/15438840/mysql-error-1364-field-doesnt-have-a-default-values. us ...
- VS Code 自动修改和保存 代码风格 == eslint+prettier
最近因为用到VS Code,需要统一所有人的代码风格(前端语言js/html/css等,或者后端语言 go/python等也可以这么用). 所以参考了一些网络资料,记录下设置步骤,以便后续查阅. St ...
- 深入浅出《设计模式》之外观模式(C++)
前言 模式介绍 外观模式相比较之下比较简单,模式设计中定义是为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个接口是的这一子系统更加容易使用. 如果不理解呢,简单些说就是外观模式提 ...
- 【入门篇】前端框架Vue.js知识介绍
一.Vue.js介绍 1.什么是MVVM? MVVM(Model-View-ViewModel)是一种软件架构设计模式,它源于MVC(Model-View-Controller)模式,它是一种思想,一 ...