[Tutor] ex-ftp
prasad rao
prasadaraon50 at gmail.com
Tue Sep 22 06:39:25 CEST 2009
hello friends
I am trying to write a class to save a url.page.
But it is not working.It is saving the html.page.But not getting
images.I am unable to show the list (object.links).
Please take a look at it and show me how to rectify it.
import urllib2,ftplib,re
class Collect:
def __init__(self,parent):
self.parent=parent
self.links=[]
self.ims=[]
s=urllib2.urlopen(self.parent)
data=s.read()
self.data=data
a=re.compile ('<[aA].*[\'"](.*)[\'"].*>'); b=re.compile('<src
img[\'"](.+)[\'"].*')
try:
z=re.search(a,self.data).group(1)
self.links.extend(z)
except:pass
try:
y=re.search(b,self.data).group(1)
self.ims.extend(y)
except:pass
return
def save(self,data):
d=open('C:/%s .html'%self.parent[10:15],'w')
d.write(data)
return
def bring(self):
ftp=ftplib.FTP(self.parent)
ftp.login()
for x in self.ims:
data=ftp.retlines(x)
d=open('C:/%s'%x,'w')
d.write(data)
return
def show(self,z):
for x in z:
print x
return
c=Collect('http://www.asstr.org')
c.save(c.data)
c.bring()
#c.show(c.ims)
c.links
Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090922/a0af149b/attachment.htm>
More information about the Tutor
mailing list