Download image from URL list using VBA or Python

711 Views Asked by At

I am trying to download some images from some URLs. I have checked Downloading Images from URL and Renaming

VBA download file from website - popup window

GET pictures from a url and then rename the picture

Download an image from image url

Download images from URL Python

Download Images from list of urls but neither one seems to work.

I need to download them a rename them as the info below: (excel sheet) A2 name C2 link, A3 name C3 link. etc.

The thing is the site that hosts the images requests to be logged in in order to view the images. It works on any browser including IE but it seems I can't download them using

Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr) 'For 64-Bit versions of Excel
Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" _
    Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, _
    ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

in Vba.

Any idea on VBA or Python is appreciated.

PS: I have work credentials for the website so I can log on it.

I have also tried with wget -i images.txt in terminal but it downloads some unreadable 11kb files.

1

There are 1 best solutions below

0
On BEST ANSWER

I used VBA to navigate to the photo web path and shell script to download the image

Set wshShell = CreateObject("WScript.Shell")
Do
ret = wshShell.AppActivate("Save Picture")
Loop Until ret = True
WScript.Sleep 500
ret = wshShell.AppActivate("Save Picture")
If ret = True Then
ret = wshShell.AppActivate("Save Picture")
pPath = "C:\Users\user\Desktop\Images\Image1"
imgP = "Image1"
wshShell.SendKeys pPath
WScript.Sleep 1000
wshShell.SendKeys "{ENTER}"
End If