选址的桌面壁纸网站汽车主题:

下面的两个print打开调试期间

#print tag
#print attrs

#!/usr/bin/env python
import re
import urllib2
import HTMLParser
base = "http://desk.zol.com.cn"
path = '/home/mk/cars/'
star = ''
def get_url(html):
parser = 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);
print 'downloading:',res.group()
filename = path+res.group()
f = open(filename,'w+')
f.write(content)
f.close()
class parse(HTMLParser.HTMLParser):
def __init__(self,Index):
self.Index = Index;
HTMLParser.HTMLParser.__init__(self)
def handle_starttag(self,tag,attrs):
#print tag
#print attrs
if(self.Index):
if not cmp(tag,'a'):
if(len(attrs) == 4):
if(attrs[0] ==('class','pic')):
#print tag
#print attrs
new = base+attrs[1][1]
print 'found a link:',new
global star
star = new
get_url(new)
else:
if not cmp(tag,'img'):
if(attrs[0] == ('id','bigImg')):
#print tag
#print attrs
Image_url = attrs[1][1]
print 'found a picture:',Image_url
download(Image_url)
if not cmp(tag,'a'):
if (len(attrs) == 4):
if (attrs[1] == ('class','next')):
#print tag
#print attrs
next = base + attrs[2][1]
print 'found a link:',next
if (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)

唯一的缺点是,在网站上漂亮的壁纸桌面壁纸 。

。。

版权声明:本文博客原创文章,博客,未经同意,不得转载。

Python 保存爬行动物捕捉网页的更多相关文章

  1. python通过代理刷网页点击量

    python通过代理刷网页点击量 更新异常处理情况 @time 2013-0803 更新循环里计数问题和随机等待时间问题 #!/usr/bin/python #-*- coding:utf-8 -*- ...

  2. python笔记之提取网页中的超链接

    python笔记之提取网页中的超链接 对于提取网页中的超链接,先把网页内容读取出来,然后用beautifulsoup来解析是比较方便的.但是我发现一个问题,如果直接提取a标签的href,就会包含jav ...

  3. python爬取某个网页的图片-如百度贴吧

    python爬取某个网页的图片-如百度贴吧 作者:vpoet mail:vpoet_sir@163.com 注:随意copy,不用告诉我 #coding:utf-8 import urllib imp ...

  4. Python 保存数据的方法(4种方法)

    Python 保存数据的方法: open函数保存 使用with open()新建对象 写入数据(这里使用的是爬取豆瓣读书中一本书的豆瓣短评作为例子) import requests from lxml ...

  5. python 处理抓取网页乱码

    python 处理抓取网页乱码问题一招鲜   相信用python的人一定在抓取网页时,被编码问题弄晕过一阵 前几天写了一个测试网页的小脚本,并查找是否包含指定的信息. 在html = urllib2. ...

  6. Python 爬取单个网页所需要加载的地址和CSS、JS文件地址

    Python 爬取单个网页所需要加载的URL地址和CSS.JS文件地址 通过学习Python爬虫,知道根据正式表达式匹配查找到所需要的内容(标题.图片.文章等等).而我从测试的角度去使用Python爬 ...

  7. python之爬取网页数据总结(一)

    今天尝试使用python,爬取网页数据.因为python是新安装好的,所以要正常运行爬取数据的代码需要提前安装插件.分别为requests    Beautifulsoup4   lxml  三个插件 ...

  8. python python 入门学习之网页数据爬虫cnbeta文章保存

    需求驱动学习的动力. 因为我们单位上不了外网所以读新闻是那么的痛苦,试着自己抓取网页保存下来,然后离线阅读.今天抓取的是cnbeta科技新闻,抓取地址是http://m.cnbeta.com/wap/ ...

  9. API例子:用Python驱动Firefox采集网页数据

    1,引言 本文讲解怎样用Python驱动Firefox浏览器写一个简易的网页数据采集器.开源Python即时网络爬虫项目将与Scrapy(基于twisted的异步网络框架)集成,所以本例将使用Scra ...

随机推荐

  1. POJ 1325 ZOJ 1364 最小覆盖点集

    题意:有A,B两台机器, 机器A 有 n个模式(0, 1, 2....n-1),同样机器B有m个模式, 两个机器一开始的模式都为0,有k个作业(id,x,y) 表示作业编号id, 该作业必须在A机器在 ...

  2. Android NDK入门实例 计算斐波那契数列二生成.so库文件

    上一篇文章输生成了jni头文件,里面包含了本地C代码的信息,提供我们引用的C头文件.下面实现本地代码,再用ndk-build编译生成.so库文件.由于编译时要用到make和gcc,这里很多人是通过安装 ...

  3. linux zombie process相关学习

    1. zombie process是什么? zombie process是那些在系统中已经死掉的process, 通过ps -A | grep defunct可以查看系统中有多少zombie proc ...

  4. POJ 2002 点hash

    Squares Time Limit: 3500MS   Memory Limit: 65536K Total Submissions: 15489   Accepted: 5864 Descript ...

  5. 程序员的视角:java 线程(转)

    在我们开始谈线程之前,不得不提下进程.无论进程还是线程都是很抽象的概念,有一个关于进程和线程很形象的比喻能帮我们更好的理解. 进程就像个房子,房子是一个包含了特定属性的容器,例如空间大小.卧室数量等. ...

  6. NPOI 创建Excel,数据读取与写入

    <1> using System; using System.Collections.Generic; using System.Linq; using System.Web; using ...

  7. bootstrap之DumpWindowHierarchy

    DumpWindowHierarchy package io.appium.android.bootstrap.handler; import android.os.Environment; impo ...

  8. 《JavaScript设计模式与开发实践》读书笔记之单例模式

    1.单例模式 保证一个类仅有一个实例,并提供一个访问它的全局访问点 1.1 传统的单例模式 var Singleton=function(name){ this.name=name; } Single ...

  9. TextBox自定义Mac输入框类

    using System.Windows.Controls; namespace test { public class MacTextBox : TextBox { private string _ ...

  10. Cocos2d-x3.1 粒子效果演示样例

    这里把粒子的几种效果粘出来,以便以后使用 原文地址:http://blog.csdn.net/qqmcy/article/details/37511259 // // IntervalLayer.cp ...