Pulling Web CSV Data Directly Into PureBasic Program?

Just starting out? Need help? Post your questions and find answers here.
Mark1Up
User
User
Posts: 19
Joined: Thu Jun 19, 2003 9:29 pm

Pulling Web CSV Data Directly Into PureBasic Program?

Post by Mark1Up »

Hi,

I want to pull historical stock market data (comma-seperated format) from Yahoo into my PureBasic application. Is there a way I can put it directly into an array or save it to disk first and then read it in? I think I can handle parsing the data once I get it into a general string array or a disk file.

Here is an example of some CSV data from Yahoo Finance (it's free!).

http://table.finance.yahoo.com/table.csv?s=IBM&g=d

Thanks for any help or ideas :idea:,

Mark
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Pulling Web CSV Data Directly Into PureBasic Program?

Post by ricardo »

Im not sure if i understand wat you need, but i think that its simple: just use the Network commands to get the webpage and parse it.

This one works to get the data:

Code: Select all

InitNetwork()

ConnectionID = OpenNetworkConnection("table.finance.yahoo.com", 80)

If ConnectionID
  com$="GET http://table.finance.yahoo.com/table.csv?s=IBM&g=d HTTP/1.1"+Chr(13)+Chr(10)
  com$=com$+"Accept: */*"+Chr(13)+Chr(10)
  com$=com$+"Accept: text/html"+Chr(13)+Chr(10)
  com$=com$+"Host: "+host$+Chr(13)+Chr(10)
  com$=com$+"User-Agent: Yahoo CVS Parser"+Chr(13)+Chr(10)
  com$=com$+Chr(13)+Chr(10)
  Res = SendNetworkData(ConnectionID,@com$,Len(com$))

    Repeat
    Delay(10)
    Result = NetworkClientEvent(ConnectionID)
  
    Select Result
  
    Case 2
      Content$ = Space(14500)
      ReceiveNetworkData(ConnectionID,@Content$,14500)
      Ok = 1
      MessageRequester("Done!","Your Data" + Chr(13) + Chr(10) + Content$,0)
      CloseNetworkConnection(ConnectionID)
    EndSelect
    
    Until Ok = 1
EndIf
ARGENTINA WORLD CHAMPION
Mark1Up
User
User
Posts: 19
Joined: Thu Jun 19, 2003 9:29 pm

Post by Mark1Up »

Thanks Ricardo, that was more straight forward than I thought. I didn't understand how to specify the HTML commands properly. Your example is much appreciated. :D

Mark
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post by Karbon »

URLDownloadToFile_() -- I think is the Win API function, pretty much does exactly what the name suggests :-)

Handy for quick stuff.
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

Karbon wrote:URLDownloadToFile_() -- I think is the Win API function, pretty much does exactly what the name suggests :-)
Handy for quick stuff.
But in my experience it fails to much... or maybe im using it badly.

Per example, try this one:

Code: Select all

Result = URLDownloadToFile_(0,"http:\\www.wikipedia.org/wiki/PureBasic_programming_language", "result.html", 0, 0)
Here it faiils all the time and i don't know why, in the same way pages with popups fails. Some advise are welcome :D
ARGENTINA WORLD CHAMPION
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1282
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

Code: Select all

Result = URLDownloadToFile_(0,"http://www.wikipedia.org/wiki/PureBasic_programming_language", "result.html", 0, 0) 
ricardo, your above example works fine here.
(and it works every time with no problems)

Actually I have used URLDownloadToFile_() quite often and have never had problems with it.
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

Hi Paul,

But here it fails ALL the times.
Im not in slow connection and never have problems in internet, just this command, im in XP (could be this the reason?)

And i have detected that webpages with popups fails always
ARGENTINA WORLD CHAMPION
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post by LarsG »

Maybe it could be your firewall settings?!?!
Or do you have a popupkiller running in the background?!?

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

Result = URLDownloadToFile_(0,"http:\\www.wikipedia.org/wiki/PureBasic_programming_language", "result.html", 0, 0)
Why not try changing http:\\ to http://
El_Choni
plouf
Enthusiast
Enthusiast
Posts: 281
Joined: Fri Apr 25, 2003 6:35 pm
Location: Athens,Greece

Post by plouf »

i have a similar problem with this command .
i use the URLDownloadToFile() command and works OK
on every computer i have try, except on one's guy
the problem is that either it is not downloaded at all,
or with double header (after i have tweak the code trying to found out what happened)

i guess the problemm sourcing from his firewall (ZoneAlarm)
but he claims that he has shut it down ....

@Ricardo do you use ZoneAlram too ?
Christos
tkruk
User
User
Posts: 24
Joined: Sat Jun 07, 2003 1:29 am
Location: New York, USA

Post by tkruk »

Maybe it is an issue with a Proxy Server.

The code above does not work for me but it is because I have
to enter a proxy server before I can make an external connection.

I wonder if there is a way to do it through code.

Tom
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

plouf wrote:i have a similar problem with this command .
i use the URLDownloadToFile() command and works OK
on every computer i have try, except on one's guy
the problem is that either it is not downloaded at all,
or with double header (after i have tweak the code trying to found out what happened)

i guess the problemm sourcing from his firewall (ZoneAlarm)
but he claims that he has shut it down ....

@Ricardo do you use ZoneAlram too ?
Nop.
XP has some kind of 'protection' itself... but i can use the command with many urls but not with all.
I try to use a w98 that i have here and the same result, but i have to note that the w98 are connected to the XP one to get internet, so if a firewall is the problem ofcourse my w98 will be in the same.

My conclusion is that its not to reliable something that fails in some PCs, not reliable to use it in a product that you will distribute to any kind of users.
ARGENTINA WORLD CHAMPION
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

El_Choni wrote:
Result = URLDownloadToFile_(0,"http:\\www.wikipedia.org/wiki/PureBasic_programming_language", "result.html", 0, 0)
Why not try changing http:\\ to http://
Tried without success :?
ARGENTINA WORLD CHAMPION
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post by LarsG »

You can switch off the automatic firewall settings on XP by opening your network connections... right click your internet connection and choose properties.. Then go to the advanced tab and deselect the firewall option..

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

@LarsG

Yes, but i can't ask all my users to do that.
I use the protection because im permanently connected and the local lan (home lan) gets Internet from my PC.
I think this kind of configuration is very common and i feel its not very reliable to trust in this kind of API if planning to distribute software, thats why i think its a better slution to use Network commands... but i found a problem a couple days ago that i cant try to make many connections in a short period of time.
Im looking for a solution.
ARGENTINA WORLD CHAMPION
Post Reply