[Chicago] how to use multithread to download?
守株待兔
1248283536 at qq.com
Fri Jun 17 12:27:21 CEST 2011
i have written a program to download an online book:
http://www.network-theory.co.uk/docs/pytut/
import time
import urllib
import lxml.html
import os
time1=time.time()
os.mkdir('/tmp/python')
down='http://www.network-theory.co.uk/docs/pytut/'
file=urllib.urlopen(down).read()
root=lxml.html.fromstring(file)
tnodes = root.xpath("//div[@class='main']//ul/li/a")
for x in tnodes:
url='http://www.network-theory.co.uk/docs/pytut/'+x.get('href')
name=x.text
myfile=open('/tmp/python/'+name,'a')
page=urllib.urlopen(url).read()
myfile.write(page)
myfile.close()
time2=time.time()
print time2-time1
it's slow , would you mind to revise it with multithread??
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20110617/5211dd10/attachment.html>
More information about the Chicago
mailing list