I have the below code which has the list r3000
, a list of links to save as html.
Is it possible to save the files with different names using a separate list?
For example, r3000
would include the link ('http://research.investors.com/quotes/nyse-agilent-technologies-inc-a.htm?fromsearch=1') then have another list called r3000sym
that is ['a','','',...]
. Then file would be saved as a.html
.
import time
import urllib2
from urllib2 import urlopen
r3000 = ['http://research.investors.com/quotes/nyse-agilent-technologies-inc-a.htm?fromsearch=1',
'http://research.investors.com/quotes/nyse-alcoa-inc-aa.htm?fromsearch=1',
'http://research.investors.com/quotes/nasdaq-american-airlines-group-aal.htm?fromsearch=1',
'http://research.investors.com/quotes/amex-altisource-asset-mgmt-aamc.htm?fromsearch=1',
'http://research.investors.com/quotes/nyse-aarons-inc-aan.htm?fromsearch=1',
'http://research.investors.com/quotes/nasdaq-applied-optoelectronics-aaoi.htm?fromsearch=1',
'http://research.investors.com/quotes/nasdaq-a-a-o-n-inc-aaon.htm?fromsearch=1',
'http://research.investors.com/quotes/nyse-advance-auto-parts-inc-aap.htm?fromsearch=1']
def yahooKeyStats(stock):
try:
site= stock
hdr = {'User-Agent': 'Mozilla/5.0'}
req = urllib2.Request(site,headers=hdr)
page = urllib2.urlopen(req).read()
dataFile = 'a.html'
f = open(dataFile,'a')
f.write(page)
f.close()
print 'Done',stock
except Exception,e:
print str(e)
for eachStock in r3000:
yahooKeyStats(eachStock)