#coding:utf-8
import urllib
exchange=['NASDAQ','NYSE','AMEX']
for down in exchange:
    myfile=open('./'+down,'w')
    url='http://www.nasdaq.com/screening/companies- \  
by-industry.aspx?exchange='+down+'&render=download'
    file=urllib.urlopen(url).read()
    myfile.write(file)
    print ('ok',down)
    myfile.close()

it can run in ubuntu+python2.6 ,when it run in window xp+python32,the output is 
 
Traceback (most recent call last):
  File "C:\Python32\getcode.py", line 8, in <module>
    file=urllib.urlopen(url).read()
AttributeError: 'module' object has no attribute 'urlopen'

i change it into:
#coding:utf-8
import urllib.request
exchange=['NASDAQ','NYSE','AMEX']
for down in exchange:
    myfile=open('./'+down,'w')
    
url='http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange='+down+'&render=download'
    file=urllib.request.urlopen(url).read()
    myfile.write(file)
    print ('ok',down)
    myfile.close()

the output is :
Traceback (most recent call last):
  File "C:\Python32\getcode.py", line 9, in <module>
    myfile.write(file)
TypeError: must be str, not bytes

how to make it run in xp+python32?
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to