spider autohome (1)
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)的更多相关文章
- spider RPC入门指南
本部分将介绍使用spider RPC开发分布式应用的客户端和服务端. spider RPC中间件基于J2SE 8开发,因此需要确保服务器上安装了JDK 8及以上版本,不依赖于任何额外需要独立安装和配置 ...
- Scrapy:为spider指定pipeline
当一个Scrapy项目中有多个spider去爬取多个网站时,往往需要多个pipeline,这时就需要为每个spider指定其对应的pipeline. [通过程序来运行spider],可以通过修改配置s ...
- spider RPC过滤器
spider支持在请求执行前或完成后进行特殊处理,比如安全性检查.敏感字段混淆等等.为此,spider提供了BeforeFilter和AfterFilter.其执行位置如下图所示: 流水线插件配置在s ...
- spider RPC插件化体系
为了满足灵活扩展的需要,spider支持灵活的自定义插件扩展,从功能上来说,插件和过滤器的差别在于过滤器不会阻止请求的执行同时对于主程序不会有API上的影响(比如servlet 过滤器和监听器)(最多 ...
- spider RPC管理接口
为了在独立管理模式下尽可能的容易运行时排查问题,spider中间件提供了一系列restful api用于动态管理当前节点的路由,下游节点等.目前支持的RESTFUL API如下所示: 功能 服务号 R ...
- spider RPC高级特性
多租户 spider原生支持多租户部署,spider报文头对外开放了机构号.系统号两个属性用于支持多租户场景下的路由. 多租户场景下的路由可以支持下述几种模式: n 系统号: n 系统号+服务号( ...
- spider RPC安全性
spider提供了多重安全保障机制,目前主要支持接入握手校验,报文完整性校验,报文加密,报文长度检查四种机制. 接入认证 spider使用两次握手校验,其握手流程如下: 签名AES加密的方式实现. l ...
- spider RPC开发指南
协议与兼容性 spider使用java语言开发,使用Spring作为IoC容器,采用TCP/IP协议,在此基础上,结合SaaS系统模式的特性进行针对性和重点设计,以更加灵活和高效的满足多租户系统.高可 ...
- spider 配置文件参考
spider有一个配置文件spider.xml,为xml格式,spider.xml采用DTD进行管理,用于管理spider的所有特性.路由.高可用等. 配置文件支持三种不同的方式进行指定: 1. 通过 ...
随机推荐
- linux关闭防火墙
查看防火墙状态: sudo service iptables status linux关闭防火墙命令: sudo service iptables stop linux启动防火墙命令: sudo se ...
- IntelliJ IDEA 16 本地LicenseServer激活(破解)
IntelliJ IDEA 16 本地LicenseServer激活(破解) IntelliJ IDEA 是Java开发利器,用社区版不爽,干催就用旗舰版,这个是收费的,需要licence. 网上找到 ...
- php 通过变量 来调用函数
<?php function fun() { echo 'fun'; } $a = 'fun'; $a(); ?> 复制代码 上面的$a变量就是fun()函数,调用$a()和调用fun() ...
- Kindeditor为什么提交后获取不到值
LinkButton不是表单提交方式所以获取不到.如果用button submit提交方式就是form提交方式后台就能获取到值 取得编辑器的HTML内容.KindEditor的可视化操作在新创建的if ...
- JSON的故事
1.介绍JSON http://www.json.org/ https://developer.mozilla.org/zh-CN/docs/JSON 2.json的序列化和反序列化 序列化方法 va ...
- andorid 远程存储中JDK和Volley的GET和POST方法
在操作Volley的时候先添加volley.jar(包) <uses-permission android:name="android.permission.INTERNET" ...
- 01背包问题:POJ3624
背包问题是动态规划中的经典问题,而01背包问题是最基本的背包问题,也是最需要深刻理解的,否则何谈复杂的背包问题. POJ3624是一道纯粹的01背包问题,在此,加入新的要求:输出放入物品的方案. 我们 ...
- NC WebService接口开发流程
一.定义类: 接口类 包定义在public下,接口类名为I开头,Service结尾 实现类 包定义在private下,实现类名以ServiceImpl结尾 VO类 若有VO类,也放在public下 U ...
- DELPHI优秀的一些开源框架:QDAC,MORMOT,DIOCP
DELPHI优秀的一些开源框架:QDAC,MORMOT,DIOCP 程序员搞任何语言的程序开发上升到一定的层次,要想进步,必须要接触和学习使用优秀的开源框架. MORMOT封装了WINDOWS最新的H ...
- 委托 在其他类中修改form中的控件属性
通常情况下,我们需要在其他业务类中将提示信息时时显示到主界面上,可以通过以下方式 Form1.cs using System; ; i < ; i++) { cb ...