Code:

#!/usr/bin/python
# -*- coding: UTF-8 -*- import re
import urllib
import time
def getHtml(url):
""" This function just simply get all the data
by the url you get.and then decode and code
to utf-8 which you need.
"""
page = urllib.urlopen(url)
html=page.read()
uni_str = html.decode('gb2312')
utf_str = uni_str.encode('utf-8')
return utf_str def getInfo(html):
"""
This function just simply get the data from the html
and filter some data which we are interest,and then
return a list.
"""
reg = r'config = {(.+?)};'
config_re = re.compile(reg)
config_list = re.findall(config_re,html)
return config_list def getEachCar(config_lists):
""" This function will parse the data,and
then return a list include the all
information of each car,the each item
of the car's information split by '|'.
"""
each_car={}
for sp in config_lists:
config_str='{'+sp+'}'
config_str=config_str.replace("null","None")
regx=r'{"specid":\d{5},"value":.+?}'
cc=re.compile(regx)
xx=re.findall(regx,config_str)
for x in xx:
x=eval(x)
akey=repr(x['specid'])
if each_car.has_key(akey):
each_car[akey]=each_car[akey]+x["value"]+"|"
else:
each_car[akey]=x['value']
jobs=[]
for each in each_car:
ter_data="|"+each_car[each]
jobs.append(ter_data)
return jobs
if __name__ == '__main__':
# html = getHtml("http://car.autohome.com.cn/config/spec/21308.html#pvareaid=100679")
html = getHtml("http://car.autohome.com.cn/config/spec/18239.html")
config_lists=getInfo(html)
each_car=getEachCar(config_lists)
for acar in each_car:
print acar

Result:

spider autohome (1)的更多相关文章

  1. spider RPC入门指南

    本部分将介绍使用spider RPC开发分布式应用的客户端和服务端. spider RPC中间件基于J2SE 8开发,因此需要确保服务器上安装了JDK 8及以上版本,不依赖于任何额外需要独立安装和配置 ...

  2. Scrapy:为spider指定pipeline

    当一个Scrapy项目中有多个spider去爬取多个网站时,往往需要多个pipeline,这时就需要为每个spider指定其对应的pipeline. [通过程序来运行spider],可以通过修改配置s ...

  3. spider RPC过滤器

    spider支持在请求执行前或完成后进行特殊处理,比如安全性检查.敏感字段混淆等等.为此,spider提供了BeforeFilter和AfterFilter.其执行位置如下图所示: 流水线插件配置在s ...

  4. spider RPC插件化体系

    为了满足灵活扩展的需要,spider支持灵活的自定义插件扩展,从功能上来说,插件和过滤器的差别在于过滤器不会阻止请求的执行同时对于主程序不会有API上的影响(比如servlet 过滤器和监听器)(最多 ...

  5. spider RPC管理接口

    为了在独立管理模式下尽可能的容易运行时排查问题,spider中间件提供了一系列restful api用于动态管理当前节点的路由,下游节点等.目前支持的RESTFUL API如下所示: 功能 服务号 R ...

  6. spider RPC高级特性

    多租户 spider原生支持多租户部署,spider报文头对外开放了机构号.系统号两个属性用于支持多租户场景下的路由. 多租户场景下的路由可以支持下述几种模式: n  系统号: n  系统号+服务号( ...

  7. spider RPC安全性

    spider提供了多重安全保障机制,目前主要支持接入握手校验,报文完整性校验,报文加密,报文长度检查四种机制. 接入认证 spider使用两次握手校验,其握手流程如下: 签名AES加密的方式实现. l ...

  8. spider RPC开发指南

    协议与兼容性 spider使用java语言开发,使用Spring作为IoC容器,采用TCP/IP协议,在此基础上,结合SaaS系统模式的特性进行针对性和重点设计,以更加灵活和高效的满足多租户系统.高可 ...

  9. spider 配置文件参考

    spider有一个配置文件spider.xml,为xml格式,spider.xml采用DTD进行管理,用于管理spider的所有特性.路由.高可用等. 配置文件支持三种不同的方式进行指定: 1. 通过 ...

随机推荐

  1. 使用C# WinForm制作 员工打卡项目 -- S2 2.3

    新建一个员工类,存储员工的信息 新建一个List<>集合,并在load事件中实例化三个员工对象 DataGridView绑定数据源,可以显示出数据 点击查询按钮,查询工号等同于输入的数的员 ...

  2. collectionView使用细节

    1.//创建组头组尾一个方法 - (UICollectionReusableView *)stCollectionView:(UICollectionView *)collectionView vie ...

  3. Ubuntu下配置和使用github

    一.配置github环境 1.环境:Ubuntu14.04 2.申请github账号 3.安装配置git服务器: (1)安装ssh:sudo apt-get install openssh-serve ...

  4. DateTools时间插件

    import java.text.DateFormat;import java.text.ParsePosition;import java.text.SimpleDateFormat;import ...

  5. js抽奖

    http://www.aichengxu.com/view/64369 <!Doctype html><html><head><meta http-equiv ...

  6. python 静态方法,类方法 ,类的继承

    转自:  http://cowboy.1988.blog.163.com/blog/static/75105798201091141521583/ 1.关于定义类的一些奇特之处  今天在Python中 ...

  7. STL源码--Allocator学习

    内存的分配需要解决的几个问题: 1. 向系统的heap空间请求空间: 2. 考虑多线程的状态问题: 3. 考虑内存空间不足时的应对策略: 4. 考虑过多“小内存块”的碎片问题. SGI的STL底层使用 ...

  8. day7----面向对象编程进阶

    本节内容: 面向对象高级语法部分 静态方法.类方法.属性方法 类的特殊方法 反射 异常处理 Socket开发基础 静态方法 它与类唯一的关联就是需要通过类名来调用这个方法 #静态方法实际跟类没关系,不 ...

  9. codeforces 424D

    题意:给定n,m<=300的矩阵,然后求一个长宽大于2的矩形,使得是从左上角位置开始逆时针绕边框一圈的时间最少.时间的计算是:给定3个数tu,tp, td,路径上数字增加为tu,相等为tp否则为 ...

  10. QQ摄像头读取条码

    跟我学机器视觉-HALCON学习例程中文详解-QQ摄像头读取条码 第一步:插入QQ摄像头,安装好驱动(有的可能免驱动) 第二步:打开HDevelop,点击助手—打开新的Image Acquisitio ...