python32 to write file

水静流深 1248283536 at qq.com
Sun Oct 23 09:15:08 EDT 2011


code 1 can run in python2.6
#coding:utf-8
import urllib 
import lxml.html
down='http://frux.wikispaces.com/'
root=urllib.urlopen(down).read()
root=lxml.html.fromstring(root)
file=root.xpath('//a')
for i  in  file:
    str1=i.text_content()
    if str1.find('pdf')  >-1 :
        str2='http://frux.wikispaces.com/file/view/'+str1
        myfile=urllib.urlopen(str2).read()
        book=open('/tmp/'+str1,'w')
        book.write(myfile)
        book.close()

 i usr command :  2to3-3.2  ~/xml.py  -w  to get  code2

#coding:utf-8
import urllib.request, urllib.parse, urllib.error 
import lxml.html
down='http://frux.wikispaces.com/'
root=urllib.request.urlopen(down).read()
root=lxml.html.fromstring(root)
file=root.xpath('//a')
for i  in  file:
    str1=i.text_content()
    if str1.find('pdf')  >-1 :
        str2='http://frux.wikispaces.com/file/view/'+str1
        myfile=urllib.request.urlopen(str2).read()
        book=open('c:\'+str1,'w')  #  i  change it  
        book.write(myfile)
        book.close()

when i run it  in  python32,the output is  :
book=open('c:\'+str1,'w')   
invalid  syntax,what is wrong?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111023/e3ca8929/attachment.html>


More information about the Python-list mailing list