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

最终:

Python3+Fiddler爬取手机端APP(三) ————使用Appium在真机模拟爬取_第1张图片

例子:
爬取天眼查:
1.手机打开开发者模式,允许USB调试
2.cmd输入adb
在这里插入图片描述
3.下载apk
4.打开appium,拖入apk,并填上设备名
Python3+Fiddler爬取手机端APP(三) ————使用Appium在真机模拟爬取_第2张图片
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
Python3+Fiddler爬取手机端APP(三) ————使用Appium在真机模拟爬取_第3张图片
7.天眼查APP打开需向左滑动三次并点击立即体验,才能进入APP,开始搜索,使用uiautomatorviewer定位元素。
在这里插入图片描述
Python3+Fiddler爬取手机端APP(三) ————使用Appium在真机模拟爬取_第4张图片
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对拦截的包进行保存获得数据
Python3+Fiddler爬取手机端APP(三) ————使用Appium在真机模拟爬取_第5张图片

你可能感兴趣的:(python爬虫,python模块)