I want to open a webpage, check for a 2 digit number/text string on that
webpage, display that string/number, WITHOUT displaying that page in a
browser.
Any help would be appreciated.
Thanx
Will Sheppard
OPEN "C:\FTP.XXX" FOR OUTPUT AS #1 ' Temporary file. You'll see
what it does...
PRINT #1, "OPEN" '--|
PRINT #1, "(website server)" ' |
PRINT #1, "(username)" ' |
PRINT #1, "(password)" '
| -- Commands for FTP to run
PRINT #1, "GET" '
|
PRINT #1, "(HTML file)" ' |
PRINT #1, "(temporary file to save HTML file to)" ' |
PRINT #1, "BYE"
'--|
CLOSE #1
SHELL "FTP -S:C:\FTP.XXX" ' Tell FTP to
execute the C:\FTP.XXX file you just made
' If you're not on-line by this command (above), then FTP will open the
connection dialog automatically.
KILL "C:\FTP.XXX" '
Delete C:\FTP.XXX file - you don't need it anymore
OPEN "(temporary file...)" FOR INPUT AS #1 ' Open the temporary
file that was just copied in the FTP command file
DO
' Simple DO...LOOP
LINE INPUT #1, TheStringorNumber$ ' Read from file
until you get the right whatever-it-is-you-want
IF IWantThisOne% = -1 THEN EXIT DO ' If this is the
string/number you want, then exit the DO...LOOP
LOOP
CLOSE #1
' Close file
KILL "(temporary file...)" '
Delete temporary file that was copied
PRINT "String or number from webpage: "; TheStringorNumber$
END
Unfortunately, this can take a while if the HTML file is large (or even
middle-sized), but this does get it done.
Like I said, there must be another way...
Requinix
The Sheppard Residence wrote in message ...
First problem: Access to the Internet over TCP/IP. You can this do in two
ways:
a) Using of FTP (File Transfer Protocol) access over Windows 98's shipped
FTP.EXE.
Small demonstration program, how to do it:
' Perform an FTP call in BASIC
INPUT "Host name"; h$
INPUT "User name"; u$
PRINT "Password";
COLOR 0, 0 ' use hidden input
INPUT p$
COLOR 7, 0
INPUT "Local directory"; ld$
INPUT "Remote directory"; rd$
INPUT "Remote file name"; rf$
' Create a *unique* temporary file name, so this program can
' simultaneously run multiple times without conflicts
' See http://dreael.catty.ch/Deutsch/BASIC-Knowhow-Ecke/EinbettungBSY.html
for more details
tp$ = ENVIRON$("TEMP")
IF tp$ = "" THEN
PRINT "Make sure that your TEMP environment variable has been"
PRINT "set. Add a line SET TEMP=C:\TEMP to your AUTOEXEC.BAT"
SYSTEM
END IF
IF RIGHT$(tp$, 1) <> "\" THEN
tp$ = tp$ + "\"
END IF
tp$ = tp$ + "~"
FOR I% = 1 TO 3
tp$ = tp$ + CHR$(65 + CINT(INT(26! * RND)))
NEXT I%
tp$ = tp$ + MID$(TIME$, 4, 2) + RIGHT$(TIME$, 2) + ".TMP"
' create a file with FTP commands
OPEN tp$ FOR OUTPUT AS 1
PRINT #1, "user "; u$; " "; p$
PRINT #1, "bin"
PRINT #1, "cd "; rd$
PRINT #1, "lcd "; ld$
PRINT #1, "get "; rf$
PRINT #1, "bye"
CLOSE 1
' Execute FTP command: This works like in UNIX and Linux :-)
SHELL "ftp -n " + h$ + " <" + tp$
' delete temporary file
KILL tp$
END
b) Write your own HTTP user agent which fetches your Web page like Linux's
"wget" command: Check out my article
http://dreael.catty.ch/Deutsch/BASIC-Knowhow-Ecke/InternetMitQuickBASIC.html
about TCP/IP socket programming. There's also an example for accessing to a
Web server.
Note that I'm still working on this BASIC knowhow corner, a French and
English translation will follow later, so please use
http://babelfish.altavista.com/translate.dyn at the moment if you don't
speak German.
Small Instruction: You must connect to TCP port 80 (www service) and send a
request like
GET /mydirectory/myFileWithTheTwoDigits.html HTTP/1.1
Host: www.mysite.com
and then read the Web server's response.
Benefit compared to a): You don't need FTP access. Especially when your page
is generated via CGI-BIN program, you cannot access to the result via FTP.
Only HTTP protocol works.
Drawback: A little more complicate to implement and install it.
> browser.
Second problem: Extracting your two digits. This makes necessary of writing
a HTML parser which scans and interprets the syntax of HTML. Beware the
UNIX/Linux-like line terminators which only uses a CHR$(10). Hints for
successful implementation/coding: I first would develop that with a simple
OPEN statement to a local .HTM file (save your page for that purpose!).
After that I would replace the INPUT$() reading operations with the TCP/IP
socket reading call (only for version b) of above) so you get your complete
application.
Andreas