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

yipeiwu_com5年前Python爬虫

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'秒'

以上所述就是本文的全部内容了,希望大家能够喜欢。

相关文章

python爬虫爬取幽默笑话网站

python爬虫爬取幽默笑话网站

爬取网站为:http://xiaohua.zol.com.cn/youmo/ 查看网页机构,爬取笑话内容时存在如下问题: 1、每页需要进入“查看更多”链接下面网页进行进一步爬取内容每页查...

python requests爬取高德地图数据的实例

如下所示: 1.pip install requests 2.pip install lxml 3.pip install xlsxwriter import requests #想...

python3爬虫之设计签名小程序

python3爬虫之设计签名小程序

本文实例为大家分享了python3设计签名小程序的具体代码,供大家参考,具体内容如下 首先,上一下要做的效果图: 先是这样一个丑陋的界面(我尽力了的真的!) 然后随便输入名字 然后点...

python3爬取数据至mysql的方法

本文实例为大家分享了python3爬取数据至mysql的具体代码,供大家参考,具体内容如下 直接贴代码 #!/usr/local/bin/python3.5 # -*- codin...

Python3爬虫学习之将爬取的信息保存到本地的方法详解

Python3爬虫学习之将爬取的信息保存到本地的方法详解

本文实例讲述了Python3爬虫学习之将爬取的信息保存到本地的方法。分享给大家供大家参考,具体如下: 将爬取的信息存储到本地 之前我们都是将爬取的数据直接打印到了控制台上,这样显然不利于...