473,729 Members | 2,186 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1931
On Wed, May 7, 2008 at 8:22 PM, Jive Dadson <no*********@no isp.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=NY SE:APC&output=c sv')
data = page.readlines( )
data[0]
'Date,Open,High ,Low,Close,Volu me\n'
>>data[1]
'7-May-08,76.13,77.94, 75.60,76.68,950 1300\n'
>>data[1].strip().split( ',')
['7-May-08', '76.13', '77.94', '75.60', '76.68', '9501300']
>>page = urllib.urlopen( 'http://download.financ e.yahoo.com/d/quotes.csv?s=AP C&amp;f=sl1d1t1 c1ohgv&amp;e=.c sv')
data = page.readlines( )
data[0]
'"APC",76.68 ,"5/7/2008","4:01pm", +2.15,76.14,77. 94,75.60,950134 2\n'
>>data[1]
Traceback (most recent call last):
File "<pyshell#1 4>", 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*********@no isp.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*********@no isp.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
5431
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 server works OK. I've heard, that P2.3 has SSL support included in himself and also, I was trying P2.2 with pyOpenSSL wrappers and extensions, but unsuccesfuly... So, could you give me a few lines of python code which makes such things:
1
5190
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 remove old version (as well as the mx libraries I had installed). I then installed the new version as a user with the Administrator role. I know I'm technically not supposed to install to a directory with a space in the name, but it worked fine for...
15
4489
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 computations, the only data transfered is user mouse/kbd input. It works synchronously, but somehow, when I play in client window, both client and server have 17 fps, while when playing in server window, server has 44 fps while client ...
6
4923
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
7724
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 enabled me to the contacts at least list. I had to root around to discover CdoDefaultFolderContacts (though it was guessable; how could I enumerate win32com.client.constants?). I now want to work through the Contacts in Outlook patching in...
0
8927
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9289
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9210
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9156
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8159
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6026
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4798
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2694
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2166
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.