python中最常用的三大数据提取方法(1)----jsonpath

1.jsonpath是python最常用提取数据的方法之一,jsonpath用于对json格式的数据进行提取,可以理解为对字典中value值的提取,用来解析多层嵌套的json数据;JsonPath 是一种信息抽取类库,是从JSON文档中抽取指定信息的工具,提供多种语言实现版本,包括:Javascript, Python, PHP 和 Java。

2. jsonpath的安装与使用:

安装方法:pip install jsonpath

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

3.jsonpath的语法 

4.举例

{ "store": {
    "book": [ 
      { "category": "r",
        "author": "N",
        "title": "S",
        "price": 8
      },
      { "category": "f",
        "author": "E",
        "title": "S",
        "price": 22
      },
      { "category": "f",
        "author": "H",
        "title": "M",
        "isbn": "3",
        "price": 33
      },
    ],
    "bicycle": {
      "color": "white",
      "price": 5
    }
  }
}

 

5.jsonpath方法的使用举例

import jsonpath

res = requests.get(url,headers=headers)

# 把json格式字符串转换成python对象
obj = json.loads(res.text)

# 从根节点开始,匹配name节点
citylist = jsonpath.jsonpath(obj,'$..name')

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,以下是爬取猎聘python和前程无忧大数据岗位相关信息的Python代码: ## 爬取猎聘python岗位信息 ```python import requests from bs4 import BeautifulSoup url = 'https://www.liepin.com/zhaopin/?key=python' headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299' } response = requests.get(url, headers=headers) soup = BeautifulSoup(response.text, 'html.parser') job_list = soup.find_all('div', class_='job-info') for job in job_list: job_name = job.find('a', class_='job-name').text.strip() job_salary = job.find('span', class_='text-warning').text.strip() job_company = job.find('a', class_='company-name').text.strip() job_location = job.find('span', class_='area').text.strip() job_time = job.find('span', class_='time-info').text.strip() print('职位名称:', job_name) print('薪资待遇:', job_salary) print('公司名称:', job_company) print('工作地点:', job_location) print('发布时间:', job_time) print('------------------------') ``` ## 爬取前程无忧大数据岗位信息 ```python import requests from bs4 import BeautifulSoup url = 'https://search.51job.com/list/000000,000000,0000,00,9,99,大数据,2,1.html' headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299' } response = requests.get(url, headers=headers) soup = BeautifulSoup(response.text, 'html.parser') job_list = soup.select('.el') for job in job_list[1:]: job_name = job.select('.t1')[0].text.strip() job_company = job.select('.t2')[0].text.strip() job_location = job.select('.t3')[0].text.strip() job_salary = job.select('.t4')[0].text.strip() job_time = job.select('.t5')[0].text.strip() print('职位名称:', job_name) print('公司名称:', job_company) print('工作地点:', job_location) print('薪资待遇:', job_salary) print('发布时间:', job_time) print('------------------------') ``` 以上代码仅供参考,具体使用时请根据自己的需求进行修改。注意爬虫的合法性,遵守相关法律法规。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不喜欢穿格子衫的程序员

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值