Browse Source

初始化项目

罗俊辉 1 year ago
parent
commit
0229748068

+ 1 - 1
README.md

@@ -1,6 +1,6 @@
 ## automatic_crawler
 
-###### python+appium+chromedriver 模拟人类新闻采集爬虫
+###### python+appium+chromedriver 模拟人类行为采集爬虫
 
 ### common   
 通用功能

+ 1 - 0
application/config/__init__.py

@@ -0,0 +1 @@
+from .ipconfig import ip_config

+ 30 - 0
application/config/ipconfig.py

@@ -0,0 +1,30 @@
+"""
+ipconfig
+每一个容器和手机需要在同一个局域网,保证容器内appium和手机的网络通畅
+"""
+
+
+def ip_config():
+    ip_dict = {
+        "machine_01": "",
+        "machine_02": "",
+        "machine_03": "",
+        "machine_04": "",
+        "machine_05": "",
+        "machine_06": "",
+        "machine_07": "",
+        "machine_08": "",
+        "machine_09": "",
+        "machine_10": "",
+        "machine_11": "",
+        "machine_12": "",
+        "machine_13": "",
+        "machine_14": "",
+        "machine_15": "",
+        "machine_16": "",
+        "machine_17": "",
+        "machine_18": "",
+        "machine_19": "",
+        "machine_20": ""
+    }
+    return ip_dict

+ 7 - 0
application/config/mobile_config.py

@@ -0,0 +1,7 @@
+"""
+key: 手机的id
+value: {
+    "wechat_account": 123456789,
+    "machine_ip":""
+}
+"""

+ 0 - 0
application/items/items.py → application/items/item.py


+ 0 - 0
application/items/item_dev.py


+ 120 - 1
application/spider/ad_click/piaoquan_tv_v1.py

@@ -1 +1,120 @@
-import time
+# -*- coding: utf-8 -*-
+# @Author: luojunhui
+# @Time: 2023/12/14
+import time
+
+from appium import webdriver
+from appium.webdriver.extensions.android.nativekey import AndroidKey
+from selenium.webdriver.common.by import By
+
+
+class PQuanTv(object):
+    def __init__(self):
+        self.platform = "票圈|3亿人喜欢的视频平台"
+        self.caps = {
+            "platformName": "Android",
+            "deviceName": "Android",
+            "appPackage": "com.tencent.mm",
+            "appActivity": ".ui.LauncherUI",
+            "autoGrantPermissions": True,
+            "unicodekeyboard": True,
+            "resetkeyboard": True,
+            "noReset": True,
+            "recreateChromeDriverSessions": True,
+            "printPageSourceOnFailure": True,
+            "newCommandTimeout": 6000,
+            "automationName": "UiAutomator2",
+            "showChromedriverLog": True,
+            "chromeOptions": {"androidProcess": "com.tencent.mm:tools"},
+            "enableWebviewDetailsCollection": True,
+            "setWebContentsDebuggingEnabled": True,
+            "chromedriverExecutable": "/usr/bin/chromedriver",
+        }
+        self.driver = webdriver.Remote("http://localhost:4750/wd/hub", self.caps)
+
+    def open_wechat(self):
+        self.driver.implicitly_wait(1)
+        for i in range(5):
+            if self.driver.find_elements(By.ID, "com.tencent.mm:id/f2s"):
+                break
+            elif self.driver.find_element(By.ID, "com.android.systemui:id/dismiss_view"):
+                self.driver.find_element(By.ID, "com.android.system:id/dismiss_view").click()
+            else:
+                pass
+        self.driver.find_elements(By.XPATH, '//*[@text="{}"]'.format(self.platform))[-1].click()
+
+    def click_ad(self):
+        elements = self.driver.find_elements(By.ID, "com.tencent.mm:id/fhs")
+        print(elements)
+        elements[0].click()
+        return
+
+
+class PQuanTvDev(object):
+    def __init__(self, rule_dict):
+        self.platform = "票圈|3亿人喜欢的视频平台"
+        self.rule_dict = rule_dict
+        self.caps = {
+            "platformName": "Android",
+            "deviceName": "Android",
+            "appPackage": "com.tencent.mm",
+            "appActivity": ".ui.LauncherUI",
+            "autoGrantPermissions": True,
+            "unicodekeyboard": True,
+            "resetkeyboard": True,
+            "noReset": True,
+            "recreateChromeDriverSessions": True,
+            "printPageSourceOnFailure": True,
+            "newCommandTimeout": 6000,
+            "automationName": "UiAutomator2",
+            "showChromedriverLog": True,
+            "chromeOptions": {"androidProcess": "com.tencent.mm:tools"},
+            "enableWebviewDetailsCollection": True,
+            "setWebContentsDebuggingEnabled": True,
+            "chromedriverExecutable": "/usr/bin/chromedriver",
+        }
+        self.driver = webdriver.Remote("http://localhost:4750/wd/hub", self.caps)
+
+    def open_minigram(self):
+        self.driver.implicitly_wait(5)
+        for i in range(10):
+            if self.driver.find_elements(By.ID, "com.tencent.mm:id/f2s"):
+                break
+            elif self.driver.find_element(By.ID, "com.android.systemui:id/dismiss_view"):
+                self.driver.find_element(By.ID, "com.android.system:id/dismiss_view").click()
+            else:
+                pass
+        size = self.driver.get_window_size()
+        self.driver.swipe(
+            int(size["width"] * 0.5),
+            int(size["height"] * 0.2),
+            int(size["width"] * 0.5),
+            int(size["height"] * 0.8),
+            200,
+        )
+        self.driver.find_elements(By.XPATH, '//*[@text="{}"]'.format(self.platform))[-1].click()
+
+    def open_chat_box(self):
+        self.driver.implicitly_wait(10)
+        print("start open chatbox")
+        box_list = self.driver.find_elements(By.ID, "com.tencent.mm:id/hg4")
+        print(box_list)
+        if box_list:
+            box_list[0].click()
+        print("finish open chatbox")
+
+    def click_ad(self):
+        minigram = self.driver.find_elements(By.ID, "com.tencent.mm:id/b2o")
+        if minigram:
+            minigram[0].click()
+        print("成功打开小程序")
+        return
+
+
+if __name__ == "__main__":
+    Pv = PQuanTvDev(rule_dict={})
+    print("成功切换到webview")
+    Pv.open_chat_box()
+    time.sleep(10)
+    Pv.click_ad()
+

+ 0 - 0
application/spider/crawler/xng_plus.py


+ 25 - 25
docker-compose.yml

@@ -2,36 +2,36 @@ version: '3.9'
 
 services:
   appium_ad_1:
-    image: appium/appium:1.18.0-p0ad
+    image: appium/appium:1.18.0-p0
     container_name: appium_piaoquan_150
     environment:
       - REMOTE_ADB=true
-      - ANDROID_DEVICES=192.168.81.92:5555
+      - ANDROID_DEVICES=192.168.100.19:5555
     volumes:
       - /Users/luojunhui/Downloads/chromedriver-linux64-116/chromedriver:/usr/bin/chromedriver
     restart: always
     ports:
       - '4750:4723'
-  appium_ad_2:
-    image: appium/appium:1.18.0-p0ad
-    container_name: appium_piaoquan_151
-    environment:
-      - REMOTE_ADB=true
-      - ANDROID_DEVICES=192.168.81.92:5555
-    volumes:
-      - /Users/luojunhui/Downloads/chromedriver-linux64-116/chromedriver:/usr/bin/chromedriver
-    restart: always
-    ports:
-      - '4751:4723'
-
-  appium_ad_3:
-    image: appium/appium:1.18.0-p0ad
-    container_name: appium_piaoquan_152
-    environment:
-      - REMOTE_ADB=true
-      - ANDROID_DEVICES=192.168.81.92:5555
-    volumes:
-      - /Users/luojunhui/Downloads/chromedriver-linux64-116/chromedriver:/usr/bin/chromedriver
-    restart: always
-    ports:
-      - '4752:4723'
+#  appium_ad_2:
+#    image: appium/appium:1.18.0-p0ad
+#    container_name: appium_piaoquan_151
+#    environment:
+#      - REMOTE_ADB=true
+#      - ANDROID_DEVICES=192.168.81.92:5555
+#    volumes:
+#      - /Users/luojunhui/Downloads/chromedriver-linux64-116/chromedriver:/usr/bin/chromedriver
+#    restart: always
+#    ports:
+#      - '4751:4723'
+#
+#  appium_ad_3:
+#    image: appium/appium:1.18.0-p0ad
+#    container_name: appium_piaoquan_152
+#    environment:
+#      - REMOTE_ADB=true
+#      - ANDROID_DEVICES=192.168.81.92:5555
+#    volumes:
+#      - /Users/luojunhui/Downloads/chromedriver-linux64-116/chromedriver:/usr/bin/chromedriver
+#    restart: always
+#    ports:
+#      - '4752:4723'

+ 0 - 0
scheduler/auto_ads_schedule.py