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?
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to