Skip to content

Commit 4d439a9

Browse files
committed
improved the scrape tool
1 parent d12d77c commit 4d439a9

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

windows_use/agent/desktop/service.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def get_state(self,use_vision:bool=False)->DesktopState:
4545
tree_state=self.tree.get_state(root=root)
4646
if use_vision:
4747
annotated_screenshot=self.tree.annotated_screenshot(tree_state.interactive_nodes,scale=0.5)
48-
screenshot=self.screenshot_in_bytes(annotated_screenshot)
48+
screenshot=self.screenshot_in_base64(annotated_screenshot)
4949
else:
5050
screenshot=None
5151
self.desktop_state=DesktopState(apps= apps,active_app=active_app,screenshot=screenshot,tree_state=tree_state)
@@ -330,7 +330,10 @@ def multi_edit(self,elements:list[tuple[int,int,str]|tuple[int,str]]):
330330
def scrape(self,url:str)->str:
331331
response=requests.get(url,timeout=10)
332332
html=response.text
333-
content=markdownify(html=html)
333+
content=markdownify(html=html,heading_style='ATX',
334+
strip=['script','style'],bullets="-",escape_astrisks=False,
335+
escape_underscores=False,escape_misc=False,autolinks=False,
336+
default_title=False,keep_inline_images_in=[])
334337
return content
335338

336339
def get_app_size(self,control:uia.Control):
@@ -434,7 +437,7 @@ def get_screen_size(self)->Size:
434437
width, height = uia.GetScreenSize()
435438
return Size(width=width,height=height)
436439

437-
def screenshot_in_bytes(self,screenshot:PILImage)->bytes:
440+
def screenshot_in_base64(self,screenshot:PILImage)->bytes:
438441
buffer=BytesIO()
439442
screenshot.save(buffer,format='PNG')
440443
img_base64 = base64.b64encode(buffer.getvalue()).decode('utf-8')
@@ -449,11 +452,9 @@ def get_screenshot(self,scale:float=0.7)->Image.Image:
449452

450453
@contextmanager
451454
def auto_minimize(self):
452-
SW_MINIMIZE=6
453-
SW_RESTORE = 9
454455
try:
455456
handle = uia.GetForegroundWindow()
456-
uia.ShowWindow(handle, SW_MINIMIZE)
457+
uia.ShowWindow(handle, win32con.SW_MINIMIZE)
457458
yield
458459
finally:
459-
uia.ShowWindow(handle, SW_RESTORE)
460+
uia.ShowWindow(handle, win32con.SW_RESTORE)

0 commit comments

Comments
 (0)