This article describes how to use Python to capture the CSS template of the template House and package the code into a zip file. it uses a single thread and is very simple and practical. here we will share it with you, for more information, see. The Python version is 2.7.9. if it is successfully tested on win8, it is a little slow to capture. if you want to use multiple threads, you have to wait. The url parameter on the website of the template home does not match the page number. if you are too lazy to perform analysis, change the url in the code. Do not spray!
The code is as follows:
#! /Usr/bin/env python
#-*-Coding: UTF-8 -*-
# By ustcwq
#2015-03-15
Import urllib, urllib2, OS, time
From bs4 import BeautifulSoup
Start = time. clock ()
Path = OS. getcwd () + u'/template home capture template /'
If not OS. path. isdir (path ):
OS. mkdir (path)
Url = "http://www.cssmoban.com/cssthemes/index_80.shtml" # How are the numbers behind the index in the source website organized?
Theme_url = 'http: // www.cssmoban.com/cssthemes /'
Response = urllib2.urlopen (url)
Soup = BeautifulSoup (response)
Result = soup. select ('P [class = "title"] ')
Print result
For item in result:
Link = item ['href ']
# Down_name = item. text # file name
New_url = theme_url + link. split ('/') [-1]
Response = urllib2.urlopen (new_url)
Soup = BeautifulSoup (response)
Result = soup. select ('. btn ')
Down_url = result [1] ['href '] # File link
Local = path+time.strftime('policy?m=d=h?m=s', time.localtime(time.time({{}}'.zip'
Urllib. urlretrieve (down_url, local) # remote save function
End = time. clock ()
Print U' template capture complete! '
Print u'total Time: ', end-start, U' second'
The above is all the content of this article. I hope you will like it.