Python3+Fiddler爬取手机端APP(三) ————使用Appium在真机模拟爬取

#####环境配置
参考文章:
https://www.cnblogs.com/ydnice/p/5787800.html
https://blog.csdn.net/xuxunxiong954/article/details/79434594
https://www.cnblogs.com/xiaoxi-3-/p/7941253.html

最终:

在这里插入图片描述

例子:
爬取天眼查:
1.手机打开开发者模式,允许USB调试
2.cmd输入adb
在这里插入图片描述
3.下载apk
4.打开appium,拖入apk,并填上设备名
在这里插入图片描述
5.写对应python程序

import selenium
import time
from appium import webdriver

class MyTestApp(object):
    def setUp(self):
        print('selenium version = ', selenium.__version__)
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '21'
        desired_caps['deviceName'] = '5JPDU17911000775'              
        desired_caps['appPackage'] = 'com.tianyancha.skyeye'                                  
        desired_caps['appActivity'] = 'com.tianyancha.skyeye.SplashPage'                       
        desired_caps['app'] = 'C://Users/Administrator/Desktop/test.apk'
        desired_caps["unicodeKeyboard"] ="True"
        desired_caps["resetKeyboard"] ="True"
        self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)

6.启动appium后启动程序,手机即可自动打开天眼查APP
在这里插入图片描述
7.天眼查APP打开需向左滑动三次并点击立即体验,才能进入APP,开始搜索,使用uiautomatorviewer定位元素。
在这里插入图片描述
在这里插入图片描述
8.进入后找到输入框输入公司名字即可,程序如下:


import selenium
import time
from appium import webdriver

class MyTestApp(object):


    def setUp(self):

        print('selenium version = ', selenium.__version__)
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '21'
        desired_caps['deviceName'] = '5JPDU17911000775'                   #127.0.0.1:62001
        desired_caps['appPackage'] = 'com.tianyancha.skyeye'                                  
        desired_caps['appActivity'] = 'com.tianyancha.skyeye.SplashPage'                       #com.tianyancha.skyeye.SplashPage
        desired_caps['app'] = 'C://Users/Administrator/Desktop/test.apk'
        desired_caps["unicodeKeyboard"] ="True"
        desired_caps["resetKeyboard"] ="True"

        self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
        time.sleep(5)
        for i in range(3):
            print(i)
            self.driver.swipe(900,900,100,900,duration=2000)
            time.sleep(3)
        self.driver.find_element_by_id('com.tianyancha.skyeye:id/launch_btn').click()
        time.sleep(2)
        self.driver.find_element_by_id('com.tianyancha.skyeye:id/txt_search_copy1').click()
        time.sleep(2)
        for i in range(10):
            self.driver.find_element_by_id('com.tianyancha.skyeye:id/search_input_et').send_keys(u'百度网讯')
            time.sleep(2)
            self.driver.find_element_by_id('com.tianyancha.skyeye:id/search_clean_iv').click()
            # self.driver.find_element_by_id('com.tianyancha.skyeye:id/search_input_et').clear()
            # self.driver.tap([(50,135)])

if __name__ == '__main__':
    mt = MyTestApp()
    mt.setUp()

9.可以使用fiddler的Fiddler ScriptEditor对拦截的包进行保存获得数据
在这里插入图片描述

  • 2
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值