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! 没想到有些人看不懂 这就算了 还来骂我 早些时候关注我的小伙伴应该知道我第一 ...
随机推荐
- Open3D-PointNet2-Semantic3D-master的运行
1.修改download_semantic3d.sh文件 #!/bin/bash ans=`dpkg-query -W p7zip-full` if [ -z "$ans" ]; ...
- nextjs作为koa中间件的使用
react客户端渲染的缺点:首屏速度慢,对SEO不友好 浏览器请求步骤 客户端跳转 1. ...
- arduino (3) 控制sim900A发送短信
狗屎佳世通旗舰店,卖的什么破玩意sim900a芯片,不支持联通卡,还生明模块支持双卡的 之前买的esp8266-07都是内存偷工减料 买的液体浊度传感器给的原理图也不给基本接线. 差评垃圾店,你敢卖就 ...
- 『卧槽』意外发现了 Hashtable 的 foreach 用法 BUG
这段时间,公司项目中 遇到一个问题,最后查出: 是 Hashtable 的用法导致的. private static void AutoCleanCache() { try { lock (m_Has ...
- 为Azure DevOps Server (TFS) 配置安全访问(HTTPS with SSL)
Contents 1. 概述 2. HTTP和HTTS比较 支持HTTP和HTTPS两种方式 要求所有连接使用HTTPS 优点: 缺点: 3. 为Azure DevOps Server 配置安全访问 ...
- 行为驱动:Cucumber + Java - 实现数据的参数化
1.什么是参数化 实际设计测试用例过程中,我们经常会用等价类.边界值这样的方法,针对一个功能进行测试数据上的测试,比如一个输入框,正向数据.逆向数据,非法输入等等 2.Cucumber的数据驱动 同上 ...
- python 使用队列实现线程同步
#通过queue的方式进行线程间同步,Queue在底层通过实现了dqueue(双生队列,在字节码时实现了线程安全)实现了线程安全 from queue import Queue import time ...
- Python Jupyter 网站编辑器
Python Jupyter 网站编辑器 jupyter 是 python的网站编辑器可以直接在网页内编写python代码并执行,内置是通过ipython来调用的.很方便灵活. 安装 1.安装ipyt ...
- Kubernetes 安全概念详解
Kubernetes 安全框架 API 认证三关 • 访问K8S集群的资源需要过三关:认证.鉴权.准入控制• 普通用户若要安全访问集群API Server,往往需要证书.Token 或者用户名+密码 ...
- .NET使用本地Outlook邮箱指定邮箱用户名和密码发送邮件
1.添加Microsoft.Office.Interop.Outlook引用 2.封装发送邮件方法 using System; using System.Configuration; using Sy ...