473,385 Members | 1,782 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

web client in Python Q

Hey folks. I know approximately zero about web clients. There's a
simple task I want to do. (I think it's probably simple.) And I figure a
Python script ought to be just the ticket.

Various web services for daily stock ticker info. For example,

http://finance.google.com/finance/hi...APC&output=csv

and

http://download.finance.yahoo.com/d/...hgv&e=.csv

Those will serve up data for the stock APC. But the problem is, a
file-selection dialog pops up. I would like to have a program that
would supply a file name and download the data automatically, without
human or mouse intervention. Is that clear?

Can someone point me in the right direction?

Thankee.
Jun 27 '08 #1
4 1911
On Wed, May 7, 2008 at 8:22 PM, Jive Dadson <no*********@noisp.comwrote:
Hey folks. I know approximately zero about web clients. There's a simple
task I want to do. (I think it's probably simple.) And I figure a Python
script ought to be just the ticket.

Various web services for daily stock ticker info. For example,

http://finance.google.com/finance/hi...APC&output=csv

and

http://download.finance.yahoo.com/d/...hgv&amp;e=.csv
That should be a pretty straightforward script. Take a look at this,
and see if it helps:
>>import urllib
page = urllib.urlopen('http://finance.google.com/finance/historical?q=NYSE:APC&output=csv')
data = page.readlines()
data[0]
'Date,Open,High,Low,Close,Volume\n'
>>data[1]
'7-May-08,76.13,77.94,75.60,76.68,9501300\n'
>>data[1].strip().split(',')
['7-May-08', '76.13', '77.94', '75.60', '76.68', '9501300']
>>page = urllib.urlopen('http://download.finance.yahoo.com/d/quotes.csv?s=APC&amp;f=sl1d1t1c1ohgv&amp;e=.csv')
data = page.readlines()
data[0]
'"APC",76.68,"5/7/2008","4:01pm",+2.15,76.14,77.94,75.60,9501342\n'
>>data[1]
Traceback (most recent call last):
File "<pyshell#14>", line 1, in <module>
data[1]
IndexError: list index out of range
>>>
The urllib documentation is here: http://docs.python.org/lib/module-urllib.html
Both of those formats look pretty straightforward to parse, but if
you're dealing with more complicated CSV files, take a look at the csv
module.

--
Jerry
Jun 27 '08 #2
Thanks, Jerry! That's so cool. I actually managed to blunder through
with sockets and so forth, but this is much cleaner.

I wonder why it does not work with

http://stockcharts.com/webcgi/wb.exe?Data.web+SLW

I get a connection reset by peer error.
Jun 27 '08 #3
On Wed, May 7, 2008 at 11:22 PM, Jive Dadson <no*********@noisp.comwrote:
I wonder why it does not work with

http://stockcharts.com/webcgi/wb.exe?Data.web+SLW
It looks like that is a subscription site. That makes things more
complicated, because it means you'll need to figure out how to log in,
then probably store cookies related to your session and offer them
back up to the web server on subsequent requests. Python has modules
that help with these things (mostly in the urllib2 module if i recall
correctly), but it's not quite as straightforward as just fetching a
URL.

I don't have time to dig up an example at the moment, but if you're
still having trouble with it, I can try to pull something together
this weekend.

--
Jerry
Jun 27 '08 #4
Jerry Hill wrote:
On Wed, May 7, 2008 at 11:22 PM, Jive Dadson <no*********@noisp.comwrote:
>I wonder why it does not work with

http://stockcharts.com/webcgi/wb.exe?Data.web+SLW

It looks like that is a subscription site. That makes things more
complicated, because it means you'll need to figure out how to log in,
then probably store cookies related to your session and offer them
back up to the web server on subsequent requests. Python has modules
that help with these things (mostly in the urllib2 module if i recall
correctly), but it's not quite as straightforward as just fetching a
URL.

I don't have time to dig up an example at the moment, but if you're
still having trouble with it, I can try to pull something together
this weekend.
Thanks for the help, Jerry. I do subscribe to that service, but tapping
the data via Python may be more trouble than it's worth. I can get all
the info for stocks and ETF's from finance.google. All I am missing is
indexes. I can probably live without those. But if you want a
challenge, have at it. It would be appreciated.

Jive

Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Krzysztof Pa¼ | last post by:
Hi, I want to make simple client in phyton, which would be able to communicate with Java server using SSL sockets. There is the Java clients, which is doing this - so I'm pretty sure, that Java...
1
by: Justin Stockton | last post by:
I recently upgraded from ActivePython 2.2.2 to ActivePython 2.3.2 and I'm running into an issue importing the win32com.client module. Before installing the new version, I made sure to properly...
15
by: Michael Rybak | last post by:
hi, everyone. I'm writing a 2-players game that should support network mode. I'm now testing it on 1 PC since I don't have 2. I directly use sockets, and both client and server do...
6
by: 7stud | last post by:
My question pertains to this example: #!/usr/bin/env python import socket, sys, time host = sys.argv textport = sys.argv s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
11
by: Bill Davy | last post by:
I am trying to edit Contacts in Outlook. This is so I can transfer numbers from my address book which is an Excel spreadsheet to my mobile phone. I came across the following snippet of code which...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.