Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Download Image from Internet
#1
Guys, can you please help me to adapt the code below to download the image?

For some reason it is not working for this link in particular.


Code:
Copy      Help
;allow single instance
if(getopt(nthreads)>1) end "The thread is already running. You can end it in the 'Running items' pane."

str sf_001 sd_001 ;;variables

download image data into variable sd
int downloaded_001
rep 60 ;;repeat max 10 minutes every 10 s until success
    IntGetFile "https://www.tropicaltidbits.com/analysis/models/eps/2024111206/eps_apcpn_us_23.png" sd_001
    err 10; continue ;;if error, retry after 10 s
    downloaded_001=1
    break
if(!downloaded_001) end "failed to download"

format filename and save to file
sf_001.timeformat("C:\TEMP\teste.png")
sd_001.setfile(sf_001)
out "done"
#2
It's not the code its the server. It's giving a 403 forbidden response.
#3
had some time to look at this again and found a workaround. It involves loading the web page in a hidden web browser control and then can download

Function Download403Image
Code:
Copy      Help
if(!FileExists("C:\TEMP" 1))
,mkdir "TEMP" "C:"
if(FileExists("C:\TEMP\eps_apcpn_us_23.png"))
,del "C:\TEMP\eps_apcpn_us_23.png"
str dd=
;BEGIN DIALOG
;0 "" 0x90CA0AC8 0x0 0 0 710 470 "Dialog"
;3 ActiveX 0x54030000 0x0 0 0 710 470 "SHDocVw.WebBrowser {8856F961-340A-11D0-A96B-00C04FD705A2}"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

str controls = "3"
str ax3SHD
if(!ShowDialog(dd &sub.DlgProc &controls 0 128)) ret

#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,mac "sub.WaitForLoaded" "" hDlg
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

#sub WaitForLoaded
function hDlg

str d1.timeformat("{yyyyMMdd}00")
SHDocVw.WebBrowser we3
we3._getcontrol(id(3 hDlg))
we3.Navigate(F"https://www.tropicaltidbits.com/analysis/models/eps/{d1}/")
opt waitmsg 1
rep() 0.01; if(!we3.Busy) break
int w3=id(3 hDlg)
Htm e=htm("A" "eps_apcpn_us_23.png" "" w3 "0" 2530 0x1 3)
e.SetFocus
e.Click
opt waitmsg 1
rep() 0.01; if(!we3.Busy) break
str url=F"https://www.tropicaltidbits.com/analysis/models/eps/{d1}/eps_apcpn_us_23.png"
Htm e1=htm("IMG" url "" w3 "0" 0 0x921 3)
sub.Downloadimage(d1)
sub.WebBrowserMemoryLeakWorkaround(w3)
clo hDlg
#sub Downloadimage
function  ~d2

str filepath.expandpath("C:\TEMP\eps_apcpn_us_23.png")
int i=URLDownloadToFile(0 F"https://www.tropicaltidbits.com/analysis/models/eps/{d2}/eps_apcpn_us_23.png" filepath 0 0)
run filepath

#sub  WebBrowserMemoryLeakWorkaround
function hwndWB

SHDocVw.WebBrowser we3._getcontrol(hwndWB)
we3.Navigate("about:blank")
opt waitmsg 1
1 ;;minimal working time with YouTube was 0.3
DestroyWindow hwndWB
0.1


Forum Jump:


Users browsing this thread: 1 Guest(s)