|
@@ -3,11 +3,11 @@ import sys
|
|
|
import time
|
|
import time
|
|
|
|
|
|
|
|
import uiautomator2 as u2
|
|
import uiautomator2 as u2
|
|
|
|
|
+from cnocr import CnOcr
|
|
|
|
|
|
|
|
|
|
|
|
|
def spider_poc(serial):
|
|
def spider_poc(serial):
|
|
|
d = u2.connect(serial)
|
|
d = u2.connect(serial)
|
|
|
- d.uiautomator.start()
|
|
|
|
|
d.screen_on()
|
|
d.screen_on()
|
|
|
d.unlock()
|
|
d.unlock()
|
|
|
d.debug = False
|
|
d.debug = False
|
|
@@ -17,11 +17,49 @@ def spider_poc(serial):
|
|
|
|
|
|
|
|
time.sleep(3)
|
|
time.sleep(3)
|
|
|
|
|
|
|
|
|
|
+ """滑动一屏幕"""
|
|
|
|
|
+ # d.swipe_ext('up', scale=1)
|
|
|
|
|
+ # time.sleep(1)
|
|
|
|
|
+
|
|
|
root_dir = os.path.dirname(sys.argv[0])
|
|
root_dir = os.path.dirname(sys.argv[0])
|
|
|
- screenshot_dir = os.path.join(root_dir, "screenshots")
|
|
|
|
|
|
|
+ screenshot_name = f'screenshots/{time.time()}.png'
|
|
|
|
|
+ screenshot_dir = os.path.join(root_dir, screenshot_name)
|
|
|
d.screenshot().save(screenshot_dir)
|
|
d.screenshot().save(screenshot_dir)
|
|
|
|
|
|
|
|
|
|
+ ocr = CnOcr()
|
|
|
|
|
+ res = ocr.ocr(screenshot_dir)
|
|
|
|
|
+ # print(res)
|
|
|
|
|
+
|
|
|
|
|
+ # 找到包含“你的快拍”的元素
|
|
|
|
|
+ target_text = '你的快拍'
|
|
|
|
|
+ i = 0
|
|
|
|
|
+ for i, item in enumerate(res):
|
|
|
|
|
+ if target_text in item['text']:
|
|
|
|
|
+ break
|
|
|
|
|
+
|
|
|
|
|
+ if i < len(res) - 1:
|
|
|
|
|
+ next_text = res[i + 1]['text']
|
|
|
|
|
+ # print(f"“{target_text}”后的文字是:“{next_text}”")
|
|
|
|
|
+ print(f"昵称:{next_text}")
|
|
|
|
|
+ else:
|
|
|
|
|
+ print("未找到昵称")
|
|
|
|
|
+
|
|
|
|
|
+ """点赞"""
|
|
|
|
|
+ # d.xpath('//*[@resource-id="com.instagram.android:id/row_feed_button_like"]').click(timeout=3)
|
|
|
|
|
+ d.double_click(0.51, 0.493)
|
|
|
|
|
+ time.sleep(3)
|
|
|
|
|
+
|
|
|
|
|
+ """搜索"""
|
|
|
|
|
+ d.xpath('//*[@resource-id="com.instagram.android:id/search_tab"]/android.widget.ImageView[1]').click(timeout=3)
|
|
|
|
|
+ time.sleep(1)
|
|
|
|
|
+ d.xpath('//*[@resource-id="com.instagram.android:id/action_bar_search_edit_text"]').click(timeout=3)
|
|
|
|
|
+ d(focused=True).set_text('电子元器件')
|
|
|
|
|
+ time.sleep(3)
|
|
|
|
|
+ d.xpath('//*[@resource-id="com.instagram.android:id/row_search_profile_image"]').click(timeout=3)
|
|
|
|
|
+
|
|
|
|
|
+ """点击账户"""
|
|
|
|
|
+ d.xpath('//*[@text="帐户"]').click()
|
|
|
|
|
+
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
|
spider_poc("5D7HSG5XXCKVBI85")
|
|
spider_poc("5D7HSG5XXCKVBI85")
|
|
|
-
|
|
|