meccatronis commited on
Commit
f2d8a20
·
verified ·
1 Parent(s): 72cccfb

Upload extract_real.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. extract_real.py +100 -0
extract_real.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ OCR Simplificado - Usa visão e extrai coordenadas para clicar nos produtos
4
+ """
5
+
6
+ import json
7
+ import re
8
+ import subprocess
9
+ from pathlib import Path
10
+ from ctypes import *
11
+
12
+ # X11
13
+ X11 = CDLL("libX11.so.6")
14
+ Xtst = CDLL("libXtst.so.6")
15
+
16
+ XOpenDisplay = X11.XOpenDisplay
17
+ XOpenDisplay.restype = c_void_p
18
+ XFlush = X11.XFlush
19
+ XFlush.argtypes = [c_void_p]
20
+
21
+ XTestFakeMotionEvent = Xtst.XTestFakeMotionEvent
22
+ XTestFakeMotionEvent.argtypes = [c_void_p, c_int, c_int, c_ulong]
23
+
24
+ XTestFakeButtonEvent = Xtst.XTestFakeButtonEvent
25
+ XTestFakeButtonEvent.argtypes = [c_void_p, c_uint, c_int, c_ulong]
26
+
27
+ XKeysymToKeycode = X11.XKeysymToKeycode
28
+ XKeysymToKeycode.argtypes = [c_void_p, c_uint]
29
+ XKeysymToKeycode.restype = c_uint
30
+
31
+ display = XOpenDisplay(None)
32
+
33
+ WIDTH = 1360
34
+ HEIGHT = 768
35
+
36
+ def move(x, y):
37
+ XTestFakeMotionEvent(display, 0, x, y, 0)
38
+ XFlush(display)
39
+
40
+ def click(button=1):
41
+ XTestFakeButtonEvent(display, button, 1, 0)
42
+ XFlush(display)
43
+ import time
44
+ time.sleep(0.15)
45
+ XTestFakeButtonEvent(display, button, 0, 0)
46
+ XFlush(display)
47
+
48
+ def screenshot(path):
49
+ subprocess.run([
50
+ "ffmpeg", "-f", "x11grab",
51
+ "-video_size", f"{WIDTH}x{HEIGHT}",
52
+ "-i", ":0", "-frames:v", "1", "-y", path
53
+ ], capture_output=True)
54
+
55
+ def main():
56
+ """
57
+ Estratégia: Clicar em cada produto e capturar detalhes da página do produto
58
+ """
59
+ output_dir = Path("/tmp/taobao_products")
60
+ output_dir.mkdir(exist_ok=True)
61
+
62
+ # Coordenadas aproximadas dos produtos na tela
63
+ # 4 colunas x 3 linhas = 12 produtos visíveis
64
+ positions = [
65
+ (180, 350), (500, 350), (820, 350), (1140, 350),
66
+ (180, 550), (500, 550), (820, 550), (1140, 550),
67
+ ]
68
+
69
+ products = []
70
+
71
+ for i, (x, y) in enumerate(positions):
72
+ print(f"Produto {i+1}: clicando em ({x}, {y})")
73
+
74
+ # Clica no produto
75
+ move(x, y)
76
+ import time
77
+ time.sleep(0.3)
78
+ click(1)
79
+ time.sleep(3) # Aguarda página do produto carregar
80
+
81
+ # Screenshot da página do produto
82
+ prod_path = output_dir / f"product_{i+1}.png"
83
+ screenshot(str(prod_path))
84
+
85
+ print(f" Screenshot: {prod_path}")
86
+
87
+ # Volta para a busca
88
+ # (seria necessário implementar navegação de volta)
89
+
90
+ time.sleep(1)
91
+
92
+ if i >= 3: # Teste com 4 produtos
93
+ break
94
+
95
+ print(f"\n✅ {len(positions)} produtos capturados")
96
+ print(f"📁 {output_dir}")
97
+ print("\n💡 Analise os screenshots com a API de visão")
98
+
99
+ if __name__ == "__main__":
100
+ main()