Simple way to get a web page?

Just starting out? Need help? Post your questions and find answers here.
codefire
User
User
Posts: 38
Joined: Thu Mar 15, 2007 4:32 pm
Location: UK

Simple way to get a web page?

Post by codefire »

Does anyone know a simple way to download a webpage over the Net in PureBasic?

I'm looking for something like:

Code: Select all

GetWebPage(file, "http://www.somesite.com/page.html")
Basically I just want to get a page - I can do the processing after that.

Many thanks,
Tony
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

Code: Select all

ReceiveHTTPFile(URL$, Filename$)
This is in PB 4.20 beta only
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
codefire
User
User
Posts: 38
Joined: Thu Mar 15, 2007 4:32 pm
Location: UK

Post by codefire »

That's exactly what I need :)

Many thanks - I'll upgrade from 4.10 to 4.20 Beta later today.
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Post by Shardik »

It is not necessary to update to 4.20 Beta for ease of use, because for Windows operating systems the task of downloading the html code of a web page is also only one function call:

URLDownloadToFile_(0, @URL, @DownloadFilename, 0, 0)

A small example:

Code: Select all

URL.S = "http://www.google.com"
DownloadFilename.S = GetTemporaryDirectory() + "Test.htm"

If URLDownloadToFile_(0, @URL, @DownloadFilename, 0, 0) = #S_OK
  MessageRequester("Info", URL + " has been downloaded sucessfully into " + DownloadFilename + "!", #MB_ICONINFORMATION)
Else
  MessageRequester("Error", "The download of " + URL + " failed!", #MB_ICONERROR)
EndIf
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

@Shardik
Some AntiVirus programs have problems with URLDownloadToFile_ API :wink:
and there some problems with cache and so on. IMHO not the best way.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Post by Shardik »

ts-soft wrote:Some AntiVirus programs have problems with URLDownloadToFile_ API :wink:
That's unfortunately correct. But have you tested the new ReceiveHTTPFile() function in Exe files of PB 4.20 Beta with AntiVirus programs extensively? May be that they complain too about some function calls?
ts-soft wrote:and there some problems with cache and so on
Do you have some links for me because this would be very important for me and my customers. Fortunately I didn't have had any complaints so far for several programs in production using URLDownloadToFile().
ts-soft wrote:IMHO not the best way.
IMHO not the best way to use a new function of a Beta version in important programs. :wink: Have you taken a look into the bug section? OK, meanwhile Fred has already fixed some of the reported bugs but can you guarantee that there are not other bugs still not found or reported? :wink: I think that many programmers are still waiting for the final version and that some bugs still will be detected after most PureBASIC users have upgraded to the new PB 4.20 final...
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

Shardik wrote:Do you have some links for me because this would be very important for me and my customers. Fortunately I didn't have had any complaints so far for several programs in production using URLDownloadToFile().
The second downloads, only download from the cache, if available, so you
have to clear the cache. For websites is this no problem, but for files
downloaded in this way.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Post by Shardik »

@ts-soft,

thank you for bringing into attention the problem with possibly having to clear the cache, although this is quite straightforward:
Simply place DeleteUrlCacheEntry_(URL) before calling URLDownloadToFile(). Examples have already been posted by PB (http://www.purebasic.fr/english/viewtop ... 12&start=1) and Kiffi and teachco (http://www.purebasic.fr/german/viewtopic.php?t=12314).
Post Reply