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. BES

    自主开发一套消息中间件系统. 需求: 1.保证能在大规模分布式环境下发送接收消息. 2.消息发送者(Producer)能够简单.容易的发送Event. 3.所有的Event都能被注册监听该Event的 ...

  2. [转载] Android.Hook框架xposed开发篇

    本文转载自: http://www.52pojie.cn/thread-396793-1-1.html 原帖:http://drops.wooyun.org/tips/7488 作者:瘦蛟舞 官方教程 ...

  3. 【Jquery mobile】动态加载ListView 转

    [Jquery mobile]动态加载ListView 分类: Jquery Mobile2011-12-01 09:04 13984人阅读 评论(1) 收藏 举报 jquerylistviewmob ...

  4. linux Bash

    本文包含的命令:type.echo.evn.set.locale.read.declare / typeset.ulimit.alias.unalias.history.!.source.stty.c ...

  5. eclipse 配置黑色主题

    虽然以前也使用eclipse的黑色主题,但是配置起来稍微麻烦一点. 这里先声明,下面的方式适合最新版本的Eclipse Luna,旧的版本可以下载我提供的这个插件,并将其放在eclipse目录下的pl ...

  6. IIS mime类型 任意类型

    HTTP头   任意mime类型   .*    application/octet-stream

  7. SQL保留关键字不能用作表名

    com.microsoft.sqlserver.jdbc.SQLServerException: 关键字 'User' 附近有语法错误. 一看就是SQL语句错误,发现控制台console上打印出来的S ...

  8. MySQL数据库指定字符集

    mysql 创建数据库时指定编码很重要,很多开发者都使用了默认编码,但是我使用的经验来看,制定数据库的编码可以很大程度上避免倒入导出带来的乱码问题. 我们遵循的标准是,数据库,表,字段和页面或文本的编 ...

  9. 安装spy-debugger

  10. oracle 安装注意

    1. 本地安装oracle数据库后,并不代表可以用plsql 连接上了.. 如果安装的是64位的oracle,plsql 是不能直接连接的.. 2. 如果是64位的..需要下载一个oracle 客户端 ...