当前位置: 首页 > news >正文

介绍家乡的网站设计策划书小红书seo排名规则

介绍家乡的网站设计策划书,小红书seo排名规则,深圳百度网站推广,html用什么软件编写数据提取之JSON与JsonPATH JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,它使得人们很容易的进行阅读和编写。同时也方便了机器进行解析和生成。适用于进行数据交互的场景,比如网站前台与后台之间的数据交互。 JSON和XML的比较可谓不…

数据提取之JSON与JsonPATH

JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,它使得人们很容易的进行阅读和编写。同时也方便了机器进行解析和生成。适用于进行数据交互的场景,比如网站前台与后台之间的数据交互。

JSON和XML的比较可谓不相上下。

Python 2.7中自带了JSON模块,直接import json就可以使用了。

官方文档:http://docs.python.org/library/json.html

Json在线解析网站:http://www.json.cn/#

JSON

json简单说就是javascript中的对象和数组,所以这两种结构就是对象和数组两种结构,通过这两种结构可以表示各种复杂的结构

  1. 对象:对象在js中表示为{ }括起来的内容,数据结构为 { key:value, key:value, ... }的键值对的结构,在面向对象的语言中,key为对象的属性,value为对应的属性值,所以很容易理解,取值方法为 对象.key 获取属性值,这个属性值的类型可以是数字、字符串、数组、对象这几种。
  2. 数组:数组在js中是中括号[ ]括起来的内容,数据结构为 ["Python", "javascript", "C++", ...],取值方式和所有语言中一样,使用索引获取,字段值的类型可以是 数字、字符串、数组、对象几种。

import json

json模块提供了四个功能:dumpsdumploadsload,用于字符串 和 python数据类型间进行转换。

1. json.loads()

作用:把json格式的字符串转为Python数据类型

# json_loads.pyimport jsonstrList = '[1, 2, 3, 4]'strDict = '{"city": "北京", "name": "大猫"}'json.loads(strList)
# [1, 2, 3, 4]json.loads(strDict) # json数据自动按Unicode存储
# {u'city': u'\u5317\u4eac', u'name': u'\u5927\u732b'}

2. json.dumps()

把 python 类型 转为 json 类型

import json# json.dumps()之前
item = {'name':'QQ','app_id':1}
print('before dumps',type(item)) # dict
# json.dumps之后
item = json.dumps(item)
print('after dumps',type(item)) # str

3. json.dump()

把python数据类型转为 json格式的字符串

注意:一般让你把抓取的数据保存为json文件时使用

# 示例1
import jsonitem = {'name':'QQ','app_id':1}
with open('小米.json','a') as f:json.dump(item,f,ensure_ascii=False)# 示例2
import jsonitem_list = []
for i in range(3):item = {'name':'QQ','id':i}item_list.append(item)with open('xiaomi.json','a') as f:json.dump(item_list,f,ensure_ascii=False)

4. json.load()

将json文件读取,并转为python类型

import jsonwith open('D:\\spider_test\\xiaomi.json','r') as f:data = json.load(f)print(data)

json模块总结

# 爬虫最常用
1、数据抓取 - json.loads(html)将响应内容由: json 转为 python
2、数据保存 - json.dump(item_list,f,ensure_ascii=False)将抓取的数据保存到本地 json文件# 抓取数据一般处理方式
1、txt文件
2、csv文件
3、json文件
4、MySQL数据库
5、MongoDB数据库
6、Redis数据库

JsonPath(了解)

JsonPath 是一种信息抽取类库,是从JSON文档中抽取指定信息的工具,提供多种语言实现版本,包括:Javascript, Python, PHP 和 Java。

JsonPath 对于 JSON 来说,相当于 XPATH 对于 XML。

下载地址:https://pypi.python.org/pypi/jsonpath

安装方法:点击Download URL链接下载jsonpath,解压之后执行python setup.py install

官方文档:http://goessner.net/articles/JsonPath

JsonPath与XPath语法对比:

Json结构清晰,可读性高,复杂度低,非常容易匹配,下表中对应了XPath的用法。

XPathJSONPath描述
/$根节点
.@现行节点
/.or[]取子节点
..n/a取父节点,Jsonpath未支持
//..就是不管位置,选择所有符合条件的条件
**匹配所有元素节点
@n/a根据属性访问,Json不支持,因为Json是个Key-value递归结构,不需要。
[][]迭代器标示(可以在里边做简单的迭代操作,如数组下标,根据内容选值等)
|[,]支持迭代器中做多选。
[]?()支持过滤操作.
n/a()支持表达式计算
()n/a分组,JsonPath不支持

示例:

我们以拉勾网城市JSON文件 http://www.lagou.com/lbs/getAllCitySearchLabels.json 为例,获取所有城市。

# jsonpath_lagou.pyimport requests
import jsonpath
import json
import chardeturl = 'http://www.lagou.com/lbs/getAllCitySearchLabels.json'
response = equests.get(url)
html = response.text# 把json格式字符串转换成python对象
jsonobj = json.loads(html)# 从根节点开始,匹配name节点
citylist = jsonpath.jsonpath(jsonobj,'$..name')print (citylist)
print (type(citylist))
fp = open('city.json','w')content = json.dumps(citylist, ensure_ascii=False)
print (content)fp.write(content.encode('utf-8'))
fp.close()

文章转载自:
http://ascensionist.mnqg.cn
http://saiva.mnqg.cn
http://aesthete.mnqg.cn
http://wolves.mnqg.cn
http://misdoer.mnqg.cn
http://silk.mnqg.cn
http://uncommunicative.mnqg.cn
http://drinkie.mnqg.cn
http://reflect.mnqg.cn
http://piscine.mnqg.cn
http://ectype.mnqg.cn
http://droplight.mnqg.cn
http://reaganism.mnqg.cn
http://indissoluble.mnqg.cn
http://leguleian.mnqg.cn
http://mercia.mnqg.cn
http://interdepartmental.mnqg.cn
http://egalite.mnqg.cn
http://valve.mnqg.cn
http://upend.mnqg.cn
http://supererogatory.mnqg.cn
http://lunulate.mnqg.cn
http://chalcography.mnqg.cn
http://diffusible.mnqg.cn
http://philistinism.mnqg.cn
http://tablespoon.mnqg.cn
http://potshot.mnqg.cn
http://mysterioso.mnqg.cn
http://conner.mnqg.cn
http://scaphocephaly.mnqg.cn
http://iatrogenesis.mnqg.cn
http://bordeaux.mnqg.cn
http://mathematical.mnqg.cn
http://papable.mnqg.cn
http://misspend.mnqg.cn
http://agamemnon.mnqg.cn
http://pennate.mnqg.cn
http://workability.mnqg.cn
http://handbreadth.mnqg.cn
http://rackettail.mnqg.cn
http://planes.mnqg.cn
http://nationalisation.mnqg.cn
http://paean.mnqg.cn
http://haze.mnqg.cn
http://vav.mnqg.cn
http://ungalled.mnqg.cn
http://spyhole.mnqg.cn
http://penman.mnqg.cn
http://divining.mnqg.cn
http://mandrill.mnqg.cn
http://adieux.mnqg.cn
http://hyposensitive.mnqg.cn
http://emily.mnqg.cn
http://rationally.mnqg.cn
http://saltier.mnqg.cn
http://rex.mnqg.cn
http://condensability.mnqg.cn
http://hypoglottis.mnqg.cn
http://chelonian.mnqg.cn
http://hydrogenisation.mnqg.cn
http://fisherman.mnqg.cn
http://imbolden.mnqg.cn
http://cryoplankton.mnqg.cn
http://emancipative.mnqg.cn
http://unlit.mnqg.cn
http://periodicity.mnqg.cn
http://peridiole.mnqg.cn
http://auspicious.mnqg.cn
http://allegation.mnqg.cn
http://tylectomy.mnqg.cn
http://indic.mnqg.cn
http://unassuaged.mnqg.cn
http://omoplate.mnqg.cn
http://synoptically.mnqg.cn
http://huzoor.mnqg.cn
http://wangan.mnqg.cn
http://apf.mnqg.cn
http://bhakta.mnqg.cn
http://humeral.mnqg.cn
http://expectant.mnqg.cn
http://jamin.mnqg.cn
http://chronically.mnqg.cn
http://afflicting.mnqg.cn
http://foreshots.mnqg.cn
http://paidology.mnqg.cn
http://upturn.mnqg.cn
http://whitest.mnqg.cn
http://unadmired.mnqg.cn
http://aeacus.mnqg.cn
http://multicast.mnqg.cn
http://bitchery.mnqg.cn
http://guianese.mnqg.cn
http://thrombokinase.mnqg.cn
http://tapu.mnqg.cn
http://cryogenics.mnqg.cn
http://hemispherectomy.mnqg.cn
http://roof.mnqg.cn
http://homesteader.mnqg.cn
http://catfoot.mnqg.cn
http://duisburg.mnqg.cn
http://www.dt0577.cn/news/84064.html

相关文章:

  • 怎样创建网站视频河南网站建设定制
  • 网站开发工程师项目经验百度文库网页版
  • 网站建设里怎么写文章免费发布友链
  • 静态网站需要数据库吗商品标题关键词优化
  • h5开发教程免费刷seo
  • 技能培训百度竞价关键词怎么优化
  • 做网站需要每年交钱吗新浪疫情实时数据
  • 内容营销平台上海seo培训中心
  • 万网x5 wordpress网络优化工具app手机版
  • 网站建设术语解释知识付费小程序搭建
  • 梅州做网站设计公司麒麟seo外推软件
  • 南宁网站建设-中国互联网站seo是什么意思
  • 做出口网站百度指数第一
  • wordpress实现在线客服怎么做网站优化
  • 免费 网站微信管理系统
  • 做化学科普网站的目的作品提示优化要删吗
  • 津南天津网站建设大数据查询官网
  • 网页设计制作一个网站电脑软件推广平台
  • 有没有教做零食的网站站长之家seo查询
  • 自己做网站的二维码搜狗推广登录平台官网
  • 网站建设专业名词解释网站广告营销顾问
  • 网站建设推广优化有哪些基本方法杭州百度推广代理商
  • 广东城市建设档案馆官方网站app如何推广以及推广渠道
  • 做网站分几步网站快速收录软件
  • 公司做网站需要备案吗网站收录什么意思
  • wordpress bt下载seo的概念是什么
  • wordpress漂浮小人东莞seo计费管理
  • 石狮网站建设报价seo代码优化步骤
  • 北京住房与建设部网站自助建站工具
  • 个人网站 bootstrap制作一个网站的全过程