Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Automated HTML Download

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Automated HTML Download

    Code:
    '
    ' Get web page and store into file in the c:/tmp dir
    '
    ' I use this to pull the daily weather report
    '
    $INCLUDE "WIN32API.INC"  'include Windows API calls
    
    UNION IPAddress
          lIpaddr AS LONG
          ipAddr(4) AS BYTE
    END UNION
    
    DECLARE FUNCTION GetWx() AS LONG
    
    ' Constants (Some various other wx sites)
    $site = "iwin2.nws.noaa.gov"
    $PAGE = "/pub/data/text/FPUS66/KSTO.TXT"
    
    FUNCTION PBMAIN () AS LONG
    DIM ip AS IPAddress
    
        HOST ADDR $SITE TO ip.lIpaddr
    
        IF ip.lIpaddr <> 0 THEN
            FOR i% = 0 TO 3
                ipa$ = ipa$ +"." + LTRIM$(STR$(ip.ipAddr(i%)))
            NEXT i%
            ipa$ = MID$(ipa$,2)
            PRINT "IP ADDR = ";ipa$
            st& = GetWx()
        ELSE
            PRINT "Host Not Found"
        END IF
    
    
    END FUNCTION
    
    FUNCTION GetWx() AS LONG
    DIM x%
    DIM URL$, WebIn$
    
    
        ' Build URL
        URL$ = "GET " + $PAGE + " HTTP/1.0"
    
        hTcp& = FREEFILE
        TCP OPEN PORT 80 AT $SITE AS hTcp& TIMEOUT 3000
        IF ERR THEN
           PRINT "Bad Site... Aborted"
            EXIT FUNCTION
        END IF
    
        ' Open Logfile
        hFile& = FREEFILE
        OPEN "c:/TEMP/WX_OUT.TXT" FOR OUTPUT AS hFile&
        IF ERR THEN
           PRINT "Error opening logfile: ";ERR
        END IF
    
        PRINT "Connected. [";URL$;"]"
        TCP PRINT hTcp&, URL$
        TCP PRINT hTcp&, "User-Agent: Mozilla/4.01 [en] [Linux]
        'TCP PRINT hTcp&, "Connection: Keep-Alive"
        TCP PRINT hTcp&, "Host: " + $SITE + CHR$(13,10)
    
        'SLEEP 2000
        DO
            'WebIn$ = ""
            TCP LINE hTcp&, WebIn$
            PRINT #hFile&, WebIn$
            PRINT WebIn$
            IF EOF(hTcp&) THEN
                TCP LINE hTcp&, WebIn$
                PRINT WebIn$
                EXIT LOOP
            END IF
            IF ERR THEN
               PRINT "Error:";ERR
            END IF
    
        LOOP WHILE NOT ERR
    
        PRINT "*** END ***"
    
        TCP CLOSE hTCP&
        CLOSE hFile&
    
    END FUNCTION
    -------------
    -------
    Dane / KO6YD
Working...
X
😀
🥰
🤢
😎
😡
👍
👎