• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > 使用Python抓取模板之家的CSS模板

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

作者:hebedich 字体:[增加 减小] 来源:互联网

hebedich 通过本文主要向大家介绍了python抓取数据,python抓取网页数据,python抓取网页图片,python抓取网页内容,python抓取图片等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

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

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

</div>

您可能想查找下面的文章:

  • 利用Python抓取行政区划码的方法
  • Python抓取电影天堂电影信息的代码
  • 使用Python抓取模板之家的CSS模板
  • Python实现抓取城市的PM2.5浓度和排名
  • 使用Python抓取模板之家的CSS模板
  • 使用PYTHON接收多播数据的代码
  • 使用PYTHON接收多播数据的代码

相关文章

  • 简介Python中用于处理字符串的center()方法
  • Python最基本的输入输出详解
  • Python 字符串中的字符倒转
  • Python设计模式之单例模式实例
  • 使用Python判断质数(素数)的简单方法讲解
  • 跟老齐学Python之有容乃大的list(3)
  • Python装饰器的函数式编程详解
  • Python中有趣在__call__函数
  • python定时器(Timer)用法简单实例
  • python编写简单爬虫资料汇总

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Python下singleton模式的实现方法
    • python新手经常遇到的17个错误分析
    • Python中的闭包总结
    • python学习笔记之调用eval函数出现invalid syntax错误问题
    • Python 时间处理datetime实例
    • Python多线程学习资料
    • SQLite3中文编码 Python的实现
    • Python的内存泄漏及gc模块的使用分析
    • python进阶教程之异常处理
    • Python使用urllib2获取网络资源实例讲解

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有