how to run in xp?

守株待兔 1248283536 at qq.com
Wed Sep 28 03:24:13 EDT 2011


#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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110928/96e0569a/attachment.html>


More information about the Python-list mailing list