Results 1 to 5 of 5

Thread: Download pages/files from internet?

  1. #1
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Download pages/files from internet?

    This thinBasic script will download default thinBasic web site page locally.
    The same can be used for whatever file from internet. Just change the url.

    [code=thinbasic] uses "INet"

    dim ret as number

    ret = INET_URLDownLoad("http://www.thinbasic.com", APP_SOURCEPATH + "Home.html")

    IF ret <> %TRUE THEN
    msgbox(0, "Error: " + ret)
    END IF
    [/code]
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  2. #2

    Re: Download pages/files from internet?

    Quote Originally Posted by Eros Olmi
    This thinBasic script will download default thinBasic web site page locally.
    The same can be used for whatever file from internet. Just change the url.

    [code=thinbasic] uses "INet"

    dim ret as number

    ret = INET_URLDownLoad("http://www.thinbasic.com", APP_SOURCEPATH + "Home.html")

    IF ret <> %TRUE THEN
    msgbox(0, "Error: " + ret)
    END IF
    [/code]
    The code looks right to me, but for some reason, I can't get it to work on my computer. Using Windows XP home edtion.

    What might I be doing wrong. It doesn't produce any error messages, it just doesn't download the page.

    Thanks

    Bob

  3. #3

    Re: Download pages/files from internet?

    If you look in the folder where you saved the program you should find the downloaded html file.

    I'm running Vista & the program seems to work fine here.
    Operating System: Windows 10 Home 64-bit
    CPU: Intel Celeron N4000 CPU @ 1.10GHz
    Memory: 4.00GB RAM
    Graphics: Intel UHD Graphics 600

  4. #4

    Re: Download pages/files from internet?

    The page will [download] AKASave to file)... EG, it will not [doanload & display] AKALaunch a viewer/browser.)
    INET_UrlDownload = Save to file. (If no path is set, it saves in script location. Dont forget the "http://" on the URL and the ".htm" on the file name.)
    INET_UrlDownload ("http://www.isawhim.com", "test.htm")
    Or...
    Load directly into a STRING
    INET_UrlGetString ("http://www.isawhim.com")

    To display/launch/run the file you downloaded, you would need to launch a viewer, or you can program your own viewer. If you want to open it with MSIE or FireFox or Opera or Netscape or Chrome... etc... you can use the commands in the "OS" module, called "OS_ShellExecute", which will (launch/open) the file.

    OS_ShellExecute("open", "test.htm", "", "", 1)
    or
    OS_ShellExecute("open", "test.htm", "", ".\", 1)

    Or, you can load the file into a string, with the "File" module using the "FILE_Load" command, that loads a file in one line. That is if you wish to edit the file data, or use the HTML-Data inside the file, to display your own way.

    [code=thinbasic]USES "Console"
    USES "File"
    USES "OS"
    USES "INET"

    DIM x AS STRING

    Console_PrintLine ""
    Console_PrintLine " --- Hit any key to begin ---"
    WAITKEY

    Console_Cls
    Console_PrintLine "Loading URL to STRING from URL"
    WAITKEY (3)
    x = INET_UrlGetString ("http://www.isawhim.com")
    Console_PrintLine x
    Console_PrintLine ""
    Console_PrintLine " --- Hit any key to continue ---"
    WAITKEY

    Console_Cls
    Console_PrintLine "Loading URL to FILE from URL"
    WAITKEY (1)
    Console_PrintLine " - One moment, fetching file..."
    INET_UrlDownload ("http://www.isawhim.com", "test.htm")
    Console_PrintLine "File downloaded, check script folder for ""test.htm"" file."
    Console_PrintLine ""
    Console_PrintLine " --- Hit any key to continue ---"
    WAITKEY

    Console_Cls
    Console_PrintLine "Loading FILE to STRING from FILE"
    WAITKEY (3)
    x = ""
    x = FILE_Load("test.htm")
    Console_PrintLine x
    Console_PrintLine ""
    Console_PrintLine " --- Hit any key to continue ---"
    WAITKEY

    Console_Cls
    Console_PrintLine "Launching FILE from THIS FOLDER"
    OS_ShellExecute("open", "test.htm", "", ".\", 1)
    Console_PrintLine " - File launched..."
    Console_PrintLine ""
    Console_PrintLine " --- Hit any key to exit ---"
    WAITKEY[/code]

    Remember, these commands, most of them, are from a programs perspective. From a user perspective, "Download" is "Get it, and show it", from a program perspective, "Download" is "Get it, and put it here".

    Hope that helps a little.

    If you want to make life a little easier, you can designate a special folder in C:\ for all your experimantal file read/write operations. Or, since the default location is "Where the script is run from." Develop all scripts in a special folder.

  5. #5

    Re: Download pages/files from internet?

    Quote Originally Posted by matthew
    If you look in the folder where you saved the program you should find the downloaded html file.

    I'm running Vista & the program seems to work fine here.
    Thanks Matthew, I found it and it did work. Now to get it to come up and run when I ask it to...

    Thanks again.

    Bob

Similar Threads

  1. Do you need to download pages/files from internet?
    By ErosOlmi in forum Sources, Templates, Code Snippets, Tips and Tricks, Do you know ...
    Replies: 2
    Last Post: 17-10-2006, 22:34

Members who have read this thread: 1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •