Question on syntax for URL construction

11 views
Skip to first unread message

Denko

unread,
Dec 20, 2011, 1:02:05 AM12/20/11
to beauti...@googlegroups.com
Hi,

I wonder if someone here could tell me how to put a variable into a URL. My script goes into Yahoo Finance and grabs information about a company (the name and age of the CEO). 

import urllib2
f = open('ticker.txt') # ticker.txt is a list of company tickers. The first ticker is Aflac, AFL
line = fileobject.readline()  # This reads the first line, AFL.
page = urllib2.urlopen("http://finance.yahoo.com/q/pr?s=line+Profile")  # This is intended to read the Profile page of AFL with "http://finance.yahoo.com/q/pr?s=AFL+Profile"

The problem is line 3. What I get with this is a company with the ticker LINE, not Aflac. How do I put the variable containing AFL into the URL?

I've looked around a bit and can't find an answer. If anyone here knows, I would appreciate hearing from you.

Dan

mehdi moradi

unread,
Dec 24, 2011, 3:35:03 PM12/24/11
to beauti...@googlegroups.com
read every line of text file and then when you open url write :
for line in open text file :  
     urllib2.urlopen("http://finance.yahoo.com/q/pr?s="+line+"Profile")






Reply all
Reply to author
Forward
0 new messages