Website Select Desktop Wallpapers website for car theme:
The following two print opens at debug time
#print Tag#print Attrs
#!/usr/bin/env pythonimport reimport urllib2import htmlparserbase = "http://desk.zol.com.cn" path = '/home/mk/cars/' Star = "Def get_url (html):p Arser = Parse (False) request = Urllib2. Request (HTML) response = Urllib2.urlopen (request) resp = Response.read () parser.feed (RESP) def download (URL): content = Urllib2.urlopen (URL). read () format = ' [0-9]*\.jpg '; res = Re.search (format,url);p rint ' downloading: ', Res.group () filename = Path+res.group () f = open (filename, ' w+ ') f.write (content) F.close () class Parse (htmlparser.htmlparser):d EF __ Init__ (Self,index): self. index = index; Htmlparser.htmlparser.__init__ (self) def handle_starttag (self,tag,attrs): #print tag#print attrsif (self. Index): If not CMP (tag, ' a '): if (len (attrs) = = 4): if (attrs[0] = = (' class ', ' pic ')): #print tag#print attrsnew = base+attrs[1] [1]print ' Found a link: ', newglobal Starstar = Newget_url (new) Else:if not CMP (tag, ' img '): if (attrs[0] = = (' id ', ' bigimg ')): #print tag#print attrsimage_url = Attrs[1][1]print ' found a picture: ', Image_urldownload (Image_url)If not CMP (tag, ' a '): if (len (attrs) = = 4): if (attrs[1] = = (' class ', ' Next '): #print tag#print attrsnext = base + attrs[2][1] print ' found a link: ', nextif (star! = Next): Get_url (next) Index_url = ' http://desk.zol.com.cn/qiche/' con = Urllib2.urlopen (Index_url). Read () Parser_index = Parse (True) parser_index.feed (Con)
Just grab the beautiful wallpaper on the Desktop Wallpapers website ...
Python Crawler Web Capture Save