Problem downloading a file with Python

I am trying to automatically download a file by clicking on a link on a web page. After clicking on the link, I get the "File Download" dialog box with the "Open", "Save" and "Cancel" buttons. I would like to click the "Save" button.

I use the watsup library as follows:

from watsup.winGuiAuto import *

optDialog = findTopWindow(wantedText="File Download")

SaveButton = findControl(optDialog,wantedClass="Button", wantedText="Save")

clickButton(SaveButton)

For some reason this does not work. The interesting thing is that in the same way the code works fine by clicking the "Cancel" button, however it refuses to work with "Save" or "Open".

Does anyone know what I should do?

Thanks a lot, Sasha

+3
source share
4 answers

Sachet,

, , ( ) Windows , . , . , , Run .

+1

:

from watsup.winGuiAuto import *
optDialog = findTopWindow(wantedText="File Download")
SaveButton = findControl(optDialog, wantedClass="Button", wantedText="Submit")
clickButton(SaveButton) 
0

, . , , , . .

[EDIT] , , . BeautifulSoup HTML-, URL- Python urllib2.

0

,

The code for this link should work. It uses ctypes instead of watsup.winGuiAuto and relies on win32 calls. Here is the code:

from ctypes import *
user32 = windll.user32

EnumWindowsProc = WINFUNCTYPE(c_int, c_int, c_int)

def GetHandles(title, parent=None):
'Returns handles to windows with matching titles'
hwnds = []
def EnumCB(hwnd, lparam, match=title.lower(), hwnds=hwnds):
title = c_buffer(' ' * 256)
user32.GetWindowTextA(hwnd, title, 255)
if title.value.lower() == match:
hwnds.append(hwnd)

if parent is not None:
user32.EnumChildWindows(parent, EnumWindowsProc(EnumCB), 0)
else:
user32.EnumWindows(EnumWindowsProc(EnumCB), 0)
return hwnds

Here is an example of calling it to press the "OK" button in any window that has the title "Download Properties" (most likely there are 0 or 1 of these windows):

for handle in GetHandles('Downloads properties'):
for childHandle in GetHandles('ok', handle):
user32.SendMessageA(childHandle, 0x00F5, 0, 0) # 0x00F5 = BM_CLICK
0
source

Source: https://habr.com/ru/post/1708995/


All Articles