473,406 Members | 2,816 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,406 software developers and data experts.

stock quotes

I would like to download stock quotes from the web, store them, do
calculations and sort the results. However I am fairly new and don't have a
clue how to parse the results of a web page download. I can get to the
site, but do not know how to request the certain data need. Does anyone
know how to do this? I would really appreciate it. Thanks.
Sep 14 '06 #1
7 3002
Donlingerfelt wrote:
I would like to download stock quotes from the web, store them, do
calculations and sort the results. However I am fairly new and don't have a
clue how to parse the results of a web page download. I can get to the
site, but do not know how to request the certain data need. Does anyone
know how to do this? I would really appreciate it. Thanks.
This will get you started:
http://www.crummy.com/software/BeautifulSoup/

George

Sep 14 '06 #2
Donlingerfelt wrote:
I would like to download stock quotes from the web, store them, do
calculations and sort the results. However I am fairly new and don't have a
clue how to parse the results of a web page download. I can get to the
site, but do not know how to request the certain data need. Does anyone
know how to do this? I would really appreciate it. Thanks.

It depends:

If the HTML on the page(s) you want to process is clean and well formed it
can be pretty easy. Download elementree from:

http://effbot.org/zone/element-index.htm

This will be included in Python 2.5 standard library, but for 2.4 and
older you need to download it.

If the HTML on the page(s) is not clean or well formed. Parsing the
HTML can be "messey". There is a module called BeautifulSoup that is
pretty good at this. You will need to get it from:

http://www.crummy.com/software/BeautifulSoup/#Download

In addition you will want to use the standard library urllib module
to connect to and read the information you want to parse.

Start with urllib and get it to read your HTML first, then use either
elementtree or beautifulsoup to parse it and extract the data you
want to get.

Note: If the web page gets changed, it can break your program.

Hope information helps.

-Larry
Sep 14 '06 #3

donI would like to download stock quotes from the web, store them, do
doncalculations and sort the results. However I am fairly new and
dondon't have a clue how to parse the results of a web page download.
donI can get to the site, but do not know how to request the certain
dondata need. Does anyone know how to do this? I would really
donappreciate it.

Before you launch into a screen scraping exercise, you might want to check
around to see if there are any web services apis which already provide stock
quotes. This might be a good place to start:

http://www.programmableweb.com/

Skip
Sep 14 '06 #4
Donlingerfelt wrote:
I would like to download stock quotes from the web, store them, do
calculations and sort the results. However I am fairly new and don't have a
clue how to parse the results of a web page download. I can get to the
site, but do not know how to request the certain data need. Does anyone
know how to do this? I would really appreciate it. Thanks.

i recently wrote a moinmoin macro which i believe does exactly what you want.
even though you aren't writing a moinmoin macro, all the stuff you need is here.

usage: [[stock(amzn,goog,yhoo)]]

note that the string 'amzn,goog,yahoo' is passed in as the symbols variable and
is placed as-is onto the url. you will receive one .csv file from yahoo with
*all* the ticker info for all symbols you requested... very cool :) then for
each row in the csv file, i pull out each column (data) and set a red or green
color based on whether the stock is up or down for the day as well as providing
a link to the yahoo finance site (finance.google.com in my latest version) when
that symbol is clicked. and finally return an html table with the data.

i hope this helps you. i apologize in advance if this code doesn't come through
the newsgroup formatted properly.

import urllib
import csv
def execute(macro, symbols):
color = 'black'
try:
reader =
csv.reader(urllib.urlopen('http://finance.yahoo.com/d/quotes.csv?s=%s&f=sl1d1t1c1ohgv&e=.csv'
% symbols))
data = []
for symbol, trade, date, time, change, opened, hi, low, volume in reader:
num = float(change)
if num 0:
color = 'green'
elif num < 0:
color = 'red'
percent = 100 * float(change) / (float(trade) - float(change))
data.append('<tr><td><a
href="http://finance.yahoo.com/q?s=%s">%s</a></td><td><font color="%s">%s (%s /
%.2f%%)</font></td></tr>' % (symbol, symbol, color, trade, change, percent))
return '<table>%s</table>' % ''.join(data)
except:
return '%s: Stock information unavailable' % symbols

bryan

Sep 14 '06 #5
Larry Bates wrote:
If the HTML on the page(s) you want to process is clean and well formed it
can be pretty easy. Download elementree from:

http://effbot.org/zone/element-index.htm
and if it turns out to be messy, but you still want to use the same API,
see:

http://effbot.org/zone/element-soup.htm

</F>

Sep 14 '06 #6
Donlingerfelt wrote:
I would like to download stock quotes from the web, store them, do
calculations and sort the results. However I am fairly new and don't have a
clue how to parse the results of a web page download. I can get to the
site, but do not know how to request the certain data need. Does anyone
know how to do this? I would really appreciate it. Thanks.
Hi,

Heres's example 8.4 from the SE manual:

----------------------------------------------------------------------------------------------------------------------------------
def get_current_stock_quotes (symbols):
import urllib

url = 'http://finance.yahoo.com/q/cq?d=v1&s=' + '+'.join (symbols)

htm_page = urllib.urlopen (url)

import SE

keep = '"~[A-Z]+ [JFMAJSOND].+?%~==(10)" "~[A-Z]+
[0-9][0-2]?:[0-5][0-9][AP]M.+?%~==(10)"'

Data_Extractor = SE.SE ('<EAT' + keep)

Tag_Stripper = SE.SE ('"~<(.|\n)*?>~= " se/htm2iso.se | "~\n[
\t\n]*~=(10)" "~ +~= "')

data = Data_Extractor (Tag_Stripper (htm_page.read ()))

htm_page.close ()

return data
print get_current_stock_quotes (('GE','IBM','AAPL', 'MSFT', 'AA',
'MER'))

GE 3:17PM ET 33.15 0.30 0.90%

IBM 3:17PM ET 76.20 0.47 0.61%

AAPL 3:22PM ET 55.66 0.66 1.20%

MSFT 3:22PM ET 23.13 0.37 1.57%

AA 3:17PM ET 31.80 1.61 4.82%

MER 3:17PM ET 70.24 0.82 1.15%

-----------------------------------------------------------------------------------------------------------------------------

If this meets your requirements you'll find SE here:
http://cheeseshop.python.org/pypi/SE/2.2%20beta

Regards

Frederic

Sep 14 '06 #7
On 9/13/06, Donlingerfelt <do***********@cox.netwrote:
I would like to download stock quotes from the web, store them, do
calculations and sort the results. However I am fairly new and don't have a
clue how to parse the results of a web page download. I can get to the
site, but do not know how to request the certain data need. Does anyone
know how to do this? I would really appreciate it. Thanks.
Some have already directed to webscraping tools, but you don't need to
go that route if you can settle for using finance.yahoo.com, as you
can ask for the data in a particular format ie: plain text, csv etc...

I have also written some code that does this. As an added bonus it
also does currency conversion. Maybe the code will help get you
started:
http://badcomputer.org/unix/code/stock.html

HTH
-d
--
http://badcomputer.org
Sep 14 '06 #8

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

Similar topics

1
by: Chris Mosser | last post by:
I'm looking to add a page to my site where I can get stock quotes for the wired, but more importantly, the wireless web(ie my cell phone). I know how write the needed php and WAP application, I...
2
by: Francesco Moi | last post by:
Hello everyone, Does anyone know where I can get free stock quotes in XML format? Thanks,
8
by: Chris | last post by:
I'm currently writing a custom financial app that tracks stock purchases and values. however, I need help in retrieving stock quotes from the internet. A 20 minute delayed quote is fine. I do not...
5
by: Marty Cruise | last post by:
Other than getting stock quotes programmatically via Yahoo (http://finance.yahoo.com/d/quotes.csv? s=XXXXX&f=sl1d1t1c1ohgv&e=.csv), is there another method that will provide even more stock quote...
2
by: Phillip Vong | last post by:
I'm new at this. Anybody know where I can find out how to pull stock quotes from the Nasdaq site into my ASP site? I want my users to enter a ticker in one Textbox1 ex. MSFT and another...
5
by: kalyxo | last post by:
Hi all! For one of our web-communities we plan an offer of real time stock quotes incl. advanced notification services. I have the following questions: - Do you know of any services, that...
5
by: Mudcat | last post by:
I have done a bit of searching and can't seem to find a stock market tool written in Python that is active. Anybody know of any? I'm trying not to re-create the wheel here.
2
by: Rathorevivek | last post by:
Hi All, I am working on a financial website. I have to use real time stock quotes ticker(in Marquee format) for that.The stock exchange for which i want to extract the stock details is NSE(India)...
2
by: melvin74 | last post by:
At work we have a couple flat screens that display news and current stock info. About a week ago it stopped displaying the marquee for the stock info. Curious if anyone had any suggestions on what...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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,...

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.