使用Python抓模數板之家的CSS模板

來源:互聯網
上載者:User
Python版本是2.7.9,在win8上測試成功,就是抓取有點慢,本來想用多線程的,有事就罷了。模板之家的網站上的url參數與頁數不匹配,懶得去做分析了,就自己改代碼中的url吧。大神勿噴!

複製代碼 代碼如下:


#!/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'/模板之家抓取的模板/'
if not os.path.isdir(path):
os.mkdir(path)

url = "http://www.cssmoban.com/cssthemes/index_80.shtml" # 源網站中的index後面數字怎麼編排的?
theme_url ='http://www.cssmoban.com/cssthemes/'
response = urllib2.urlopen(url)
soup = BeautifulSoup(response)
result = soup.select('p[class="title"] a')
print result

for item in result:
link = item['href']
# down_name = item.text # 檔案名稱
new_url = theme_url+link.split('/')[-1]
response = urllib2.urlopen(new_url)
soup = BeautifulSoup(response)
result = soup.select('.btn a')
down_url = result[1]['href'] # 檔案連結

local = path+time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))+'.zip'
urllib.urlretrieve(down_url, local) # 遠程儲存函數

end = time.clock()
print u'模板抓取完成!'
print u'一共用時:',end-start,u'秒'

以上所述就是本文的全部內容了,希望大家能夠喜歡。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.