ソースを参照

spider fb data

derrickx 1 年間 前
コミット
bae3e49619

BIN
facebook/screenshots/1715094110.900465.png


BIN
facebook/screenshots/1715094163.686677.png


BIN
facebook/screenshots/1715094200.312835.png


BIN
facebook/screenshots/1715094267.727485.png


BIN
facebook/screenshots/1715094370.4556742.png


BIN
facebook/screenshots/1715094434.640671.png


BIN
facebook/screenshots/1715094522.179156.png


+ 38 - 4
facebook/spider_poc.py

@@ -3,7 +3,7 @@ import sys
 import time
 
 import uiautomator2 as u2
-
+from cnocr import CnOcr
 
 def spider_poc(serial):
     d = u2.connect(serial)
@@ -15,9 +15,43 @@ def spider_poc(serial):
     d.app_start("com.facebook.katana", use_monkey=True)
     time.sleep(3)
 
-    items = d.xpath(
-        '//*[@resource-id="android:id/list"]/android.view.ViewGroup[3]/android.view.ViewGroup[1]/android.view.ViewGroup[2]/android.view.ViewGroup[1]').get_text()
-    print(items)
+    # 搜索
+    d.xpath('//*[@content-desc="搜索"]').click(timeout=3)
+
+    # 点击搜索框
+    d.xpath('//*[@text="搜索"]').click(timeout=3)
+
+    # 输入搜索关键词
+    d(focused=True).set_text('电子元器件')
+    # 点击搜索
+    d.press('enter')
+    time.sleep(6)
+
+    # 点击帖子
+    d.xpath('//*[@content-desc="帖子个搜索结果"]').click(timeout=3)
+    time.sleep(6)
+
+    # 点击展开
+    d.click(0.461, 0.29)
+
+    # 图片识别
+    root_dir = os.path.dirname(sys.argv[0])
+    screenshot_name = f'screenshots/{time.time()}.png'
+    screenshot_dir = os.path.join(root_dir, screenshot_name)
+    d.screenshot().save(screenshot_dir)
+
+    ocr = CnOcr()
+    res = ocr.ocr(screenshot_dir)
+    # print(res)
+
+    # 找到包含“你的快拍”的元素
+    text_before_join = ""
+    for item in res:
+        if item['text'] in '加入':
+            break
+        text_before_join += item['text']
+
+    print(text_before_join)
 
 
 if __name__ == "__main__":