diff --git a/projects/App/appiumTest.py b/projects/App/appiumTest.py index ee3fb6f..a571d80 100644 --- a/projects/App/appiumTest.py +++ b/projects/App/appiumTest.py @@ -2,4 +2,76 @@ Created by 朝南而行 2019/3/8 17:21 """ -from appium import webdriver \ No newline at end of file +from appium import webdriver +from selenium.webdriver.support.ui import WebDriverWait +import time +import random + + +class AppiumQTT(object): + + def __init__(self): + self.cap = { + "platformName": "Android", + "platformVersion": "4.4.2", + "deviceName": "127.0.0.1:62001", + "appPackage": "com.jifen.qukan", + "appActivity": "com.jifen.qkbase.main.MainActivity", + "noReset": True + } + self.driver = webdriver.Remote('http://localhost:4723/wd/hub', self.cap) + time.sleep(5) + self.x = self.driver.get_window_size()['width'] + self.y = self.driver.get_window_size()['height'] + self.x1 = int(self.x * 0.5) + self.y1 = int(self.y * 0.75) + self.y2 = int(self.y * 0.25) + + def swipe_in(self): + a = 5 + while a > 0: + print('开始向上滑动=================================' + str(5-a)) + self.driver.swipe(self.x1, self.y1, self.x1, self.y2) + time.sleep(random.randint(8, 12)) + a = a - 1 + + def swipe_up(self): + b = 3 + while b > 0: + print('开始向下滑动=================================' + str(5 - b)) + self.driver.swipe(self.x1, self.y2, self.x1, self.y1) + time.sleep(random.randint(8, 12)) + b = b - 1 + + def swipe_random(self): + c = random.randint(2, 5) + while c > 0: + print('随机滑动=================================' + str(c)) + self.driver.swipe(self.x1, self.y1, self.x1, self.y2) + time.sleep(random.randint(1, 2)) + c = c - 1 + + + + def run(self): + while True: + print('开始点击列表=================================') + try: + if WebDriverWait(self.driver, 3).until(lambda x: x.find_element_by_xpath( + "//android.support.v7.widget.RecyclerView[@resource-id='com.jifen.qukan:id/pr']/android.widget.LinearLayout[1]")): + self.driver.find_element_by_xpath( + "//android.support.v7.widget.RecyclerView[@resource-id='com.jifen.qukan:id/pr']/android.widget.LinearLayout[1]").click() + except: + pass + self.swipe_in() + self.swipe_up() + # 点击返回键 + self.driver.keyevent(4) + time.sleep(3) + self.swipe_random() + + +if __name__ == '__main__': + appiumQtt = AppiumQTT() + appiumQtt.run() + diff --git a/projects/fiddler/demo01.py b/projects/fiddler/demo01.py new file mode 100644 index 0000000..0471762 --- /dev/null +++ b/projects/fiddler/demo01.py @@ -0,0 +1,89 @@ +""" + Created by 朝南而行 2018/12/5 16:36 +""" +import requests +import json +from multiprocessing import Queue + + +# 实战抓取豆果美食APP数据(引入队列) +# 创建队列 +queue_lists = Queue() + + +def handel_request(url, data): + headers = { + "client": "4", + "version": "6932.2", + "device": "OPPO R11", + "sdk": "22,5.1.1", + "imei": "866174010401657", + "channel": "zhuzhan", + "mac": "40:A5:EF:D3:A4:6C", + "resolution": "1280*720", + "dpi": "1.5", + # "android-id": " 40a5efd3a46c2350", + # "pseudo-id": " fd3a46c235040a5e", + "brand": "OPPO", + "scale": "1.5", + "timezone": "28800", + "language": "zh", + "cns": "3", + "carrier": "CHINA+MOBILE", + "imsi": "460074016523921", + "user-agent": "Mozilla/5.0 (Linux; Android 5.1.1; OPPO R11 Build/NMF26X) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/39.0.0.0 Mobile Safari/537.36", + "reach": "1", + "newbie": "0", + "Content-Type": "application/x-www-form-urlencoded; charset=utf-8", + "Accept-Encoding": "gzip, deflate", + "Connection": "Keep-Alive", + # "Cookie": " duid=58928990", + "Host": "api.douguo.net", + # "Content-Length": " 89", + } + + resp = requests.post(url=url, headers=headers, data=data) + return resp + + +def handle_index(): + url = 'http://api.douguo.net/recipe/flatcatalogs' + data = { + "client": "4", + # "_session": "1551791174767866174010401657", + # "v": "1551352576", + "_vs": "2305", + } + resp = handel_request(url=url, data=data) + index_response_dict = json.loads(resp.text) + for index_item in index_response_dict['result']['cs']: + for index_item_1 in index_item['cs']: + for item in index_item_1['cs']: + name_data = { + "client": "4", + # "_session": "1551796106507866174010401657", + "keyword": item['name'], + "order": "0", + "_vs": "400", + } + queue_lists.put(name_data) + + # print(name_data['keyword']) + + +def handle_foot_list(data): + print('当前处理的食材是:' + data['keyword']) + foot_list_url = 'http://api.douguo.net/recipe/v2/search/0/20' + foot_list_resp = requests.post(url=foot_list_url, data=data) + foot_response_dict = json.loads(foot_list_resp.text) + for foot_item in foot_response_dict['result']['list']: + foot_info = {} + foot_info['shicai'] = data['keyword'] + + +if __name__ == '__main__': + handle_index() + handle_foot_list(queue_lists.get()) + # print(queue_lists.qsize()) + + diff --git a/projects/mitmproxy/demo01.py b/projects/mitmproxy/demo01.py new file mode 100644 index 0000000..a8f87d7 --- /dev/null +++ b/projects/mitmproxy/demo01.py @@ -0,0 +1,28 @@ +""" + Created by 朝南而行 2018/12/5 16:36 +""" +from mitmproxy import ctx + + +# 必须这么写 +def request(flow): + # print(flow.request.headers) + # 日志输出 + # ctx.log.info(str(flow.request.headers)) + # ctx.log.warn(str(flow.request.url)) + ctx.log.error(str(flow.request.headers)) + ctx.log.error(str('='*20)) + ctx.log.error(str(flow.request.url)) + ctx.log.error(str('=' * 20)) + ctx.log.error(str(flow.request.host)) + ctx.log.error(str('=' * 20)) + ctx.log.error(str(flow.request.method)) + ctx.log.error(str('=' * 20)) + ctx.log.error(str(flow.request.path)) + ctx.log.error(str('=' * 20)) + + +# 必须这么写 +def response(flow): + ctx.log.error(str(flow.response.status_code)) +