Get the content of a webpage

BlitzMax Forums/BlitzMax Beginners Area/Get the content of a webpage

Vampyre(Posted 2011) [#1]
Hello guys,

I was just wondering if it was possible to get the content of a webpage with Blitzmax programmation...

Before starting to shoot at me that this is wrong, it's nothing illegal :-) I'm doing challenges on the web, and one of those challenge is to grab a number from a given webpage, grab a second number from a given second webpage, and send the answer to a third webpage, the whole in less than 1 second.

Here only programming could help, and was wondering if it was possible with Blitzmax

Thanks :-)

Vampyre


Perturbatio(Posted 2011) [#2]
it's perfectly possible, in fact I think the samples dir might even have an example of how to pull content from the web. I know the threading examples have one for images.


xlsior(Posted 2011) [#3]
Getting content from the web is easy:

Just like opening any other file, except put "http::" in front of it, and it will give you a datastream just like any other file.

One catch is that this is not seekable, so if you wish to use it with loadimage and the likes you'd have to stream the web data into a bank first.

sample to read HTML:

file=OpenFile("http::www.google.com")

If Not file RuntimeError "could not open read website

While Not Eof(file)
Print ReadLine(file)
Wend
CloseStream file


Or to display an image from a website:
Graphics 640,480
file=LoadImage(LoadBank(ReadFile("http::www.google.com/intl/en_ALL/images/srpr/logo1w.png")))
If Not file RuntimeError "could not read image"
DrawImage(file,10,10)
Flip
WaitKey()



Vampyre(Posted 2011) [#4]
Thank you for the answer :-) I knew it was possible to get an image from the web, thanks to the tutorials, but I didn't knew how to parse a text file, or even if it worked... I will have a check at the method... and have a little search on the docs on how to - truncate, as the webpage start with a text and finishes with a number, and - change only the number of the webpage into a numerical value into Blitzmax so I can use it in calculation...

It should be relatively easy though (I have already completed some of those challenges in VB...)

Thanks for letting me know :-)


degac(Posted 2011) [#5]
Yes, you can do it: I've made a program that 'scans' a wikisite to download contents... of course it works only on that site, but the basics are OpenFile (URL) and Instr() / string.Find()... and many many patience.