appium爬取微信朋友圈 安卓模拟器版
环境: 安卓7,夜神模拟器,微信7.0.7
代码:
import os
import time
from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC# 连接手机
PLATFROM = 'Android'
DEVICE_NAME = '127.0.0.1:62001 device'
APP_PACKGE = 'com.tencent.mm'
APP_ACTIVITY = '.ui.LauncherUI'
DRIVER_SERVER = 'http://localhost:4723/wd/hub'
TIMEOUT = 300class Moments():def __init__(self):# 驱动配置self.desired_caps = {'platformName': PLATFROM,'deviceName': DEVICE_NAME,'appPackage': APP_PACKGE,'appActivity': APP_ACTIVITY,"noReset": 'true'}self.driver = webdriver.Remote(DRIVER_SERVER, self.desired_caps)self.wait = WebDriverWait(self.driver, TIMEOUT)def enter(self):# 此处是一个坑,sleep时间如果设置的短,将会找不到元素,因为此时微信并没有启动time.sleep(10)el1 = self.driver.find_element_by_xpath("//android.widget.FrameLayout[@content-desc=\"当前所在页面,与的聊天\"]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.RelativeLayout[3]/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.ImageView")el1.click()time.sleep(3)el2 = self.driver.find_element_by_xpath("//android.widget.FrameLayout[@content-desc=\"当前所在页面,与的聊天\"]/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.FrameLayout/com.tencent.mm.ui.mogic.WxViewPager/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.ListView/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.LinearLayout")el2.click()self.crawl()def crawl(self):# 滑动点FLICK_START_X = 300FLICK_START_Y = 300FLICK_DISTANCE = 600while True:# 上滑self.driver.swipe(FLICK_START_X, FLICK_START_Y + FLICK_DISTANCE, FLICK_START_X, FLICK_START_Y)# 当前页面显示的所有状态items = self.wait.until(EC.presence_of_all_elements_located((By.XPATH, '//android.widget.FrameLayout[@content-desc="当前所在页面,朋友圈"]/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.ListView')))# 遍历每条状态for item in items:try:# 昵称nickname = item.find_element_by_id('com.tencent.mm:id/bag').get_attribute('text')# 正文content = item.find_element_by_id('com.tencent.mm:id/f3o').get_attribute('text')if content == '':passelse:print(nickname+':', content)f = open('contents.txt','a',encoding='utf-8')f.write('%s' % nickname + ':' +'%s' % content)f.write('\n' + '-------------------------------------------------------------------------------------------------------------------------------------------------' + '\n')time.sleep(3)except NoSuchElementException:passif __name__ == "__main__":start = Moments()start.enter()
坑:
1、遇到找不到元素的情况可以考虑一下app的启动问题(指定页面没有打开的话,是找不到元素的),可以加time.sleep()解决。
2、安卓5老是连接失败(Could not proxy command to remote server. Original error:socket hang up)(安卓7,安卓9没问题),但是可以获取到微信朋友圈的时间信息,安卓7以上,无法获取到时间信息。
appium爬取微信朋友圈 安卓模拟器版相关推荐
- appium爬取微信朋友圈信息 真机测试
坏境: 安卓9,荣耀10,微信7.0.11 代码: from appium import webdriver from selenium.webdriver.support.ui import Web ...
- Python3+Appium爬取微信朋友圈信息
from appium import webdriver from selenium.webdriver.support.ui import WebDriverWait#可以通过xpath定位元素 f ...
- Python爬虫实战项目案例——爬取微信朋友圈
项目实战 Appium爬取微信朋友圈 自动化爬取App数据 基于移动端的自动化测试工具Appium的自动化爬取程序. 步骤 1.JDK - Download JDK,Appium要求用户必须配 ...
- Python爬虫爬取微信朋友圈的方法,感兴趣的朋友可以了解下
前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 小雨 | 作者 python教程 | 来源 接下来,我们将实现微信朋友圈的 ...
- Python爬虫爬取微信朋友圈
更多编程教程请到:菜鸟教程 https://www.piaodoo.com/ 友情链接: 高州阳光论坛https://www.hnthzk.com/ 人人影视http://www.op-kg.com/ ...
- python抓取朋友圈动态_如何利用Python网络爬虫爬取微信朋友圈动态--附代码(下)...
原标题:如何利用Python网络爬虫爬取微信朋友圈动态--附代码(下) 前天给大家分享了如何利用Python网络爬虫爬取微信朋友圈数据的上篇(理论篇),今天给大家分享一下代码实现(实战篇),接着上篇往 ...
- Python爬取微信朋友圈 ! 让屏蔽你的女神无处可躲 ?
接下来,我们将实现微信朋友圈的爬取. 如果直接用 Charles 或 mitmproxy 来监听微信朋友圈的接口数据,这是无法实现爬取的,因为数据都是被加密的.而 Appium 不同,Appium 作 ...
- 如何利用Python网络爬虫爬取微信朋友圈动态--附代码(下)
前天给大家分享了如何利用Python网络爬虫爬取微信朋友圈数据的上篇(理论篇),今天给大家分享一下代码实现(实战篇),接着上篇往下继续深入. 一.代码实现 1.修改Scrapy项目中的items.py ...
- python朋友圈动态_如何利用Python网络爬虫爬取微信朋友圈动态--附代码(下)
前天给大家分享了如何利用Python网络爬虫爬取微信朋友圈数据的上篇(理论篇),今天给大家分享一下代码实现(实战篇),接着上篇往下继续深入. 一.代码实现 1.修改Scrapy项目中的items.py ...
最新文章
- catia怎么创建约束快捷键_答疑 | CATIA结构树无法显示怎么办?
- android堆栈信息,android死锁致重启问题分析
- WF4.0进行单元测试
- 浅析python 中__name__ = '__main__' 的作用
- 查拉斯图拉的“没落”
- C语言:关键字volatile详解!
- node.js初探-超越昨天的自己系列(3)
- oss多线程 上传_解读阿里云oss-android/ios-sdk 断点续传(多线程)
- mysql 保留两位小数
- MOCTF-Web-一道水题
- buffer java nio_Java NIO深入理解Buffer(缓冲区)
- visual c语言编译运行结果,Visual Studio 2015编译运行C语言文件问题小结
- y480 linux无线网卡驱动,联想y480无线网卡驱动下载
- 如何基于FastReport报表工具,生成报表PDF文档展示医院处方笺的内容
- 【Cubase11】音乐工作站:宿主软件 - 基础入门笔记
- error obtaining controller instance: failed to create NAT chain
- 小仙女讲JVM(1)—综述
- 引导区坏 计算机无法启动,小白告诉你Win10无法正常启动修复引导文件教程
- Virtualbox拓展包安装失败
- Excel中按多个符号进行分列