爬虫:jsonpath模块及腾讯招聘数据获取

目录

jsonpath模块

腾讯招聘数据获取


jsonpath模块

复制代码
# pip install jsonpath -i https://pypi.tuna.tsinghua.edu.cn/simple
import jsonpath

data = {
    "store": {
        "book":
            [{
            "category": "reference",
            "author": "Nigel Rees",
            "title": "Sayings of the Century",
            "price": 8.95
            },{
            "category": "fiction",
            "author": "Evelyn Waugh",
            "title": "Sword of Honour",
            "price": 12.99
            },{
            "category": "fiction",
            "author": "Herman Melville",
            "title": "Moby     Dick",
            "isbn": "0-553-21311-3",
            "price": 8.99
            }, {
            "category": "fiction",
            "author": "J. R. R. Tolkien",
            "title": "The Lord of the Rings",
            "isbn": "0-395-19395-8",
            "price": 22.99
            }],
            "bicycle":
                {"color": "red",
                "price": 19.95}
    }
}
# print(data['store']['book'][0]['title'])
# print(jsonpath.jsonpath(data,'$.store.book[*].title'))
# print(jsonpath.jsonpath(data,'$..title'))

# 在jsonpath下标中,正数下标可以直接用,负数下标要通过切片来使用
# print(jsonpath.jsonpath(data,'$.store.book[-1].title')) # False
# print(jsonpath.jsonpath(data,'$.store.book[-1:].title'))
# print(jsonpath.jsonpath(data,'$.store.book[-2:-1].title')) #获取倒数第二个
# (@.length):获取当前元素的长度
# print(jsonpath.jsonpath(data,'$.store.book[(@.length-1)].title'))

# print(jsonpath.jsonpath(data,'$..book[?(@.isbn)]'))
print(jsonpath.jsonpath(data,'$..book[?(@.price>10)]'))

腾讯招聘数据获取

复制代码
from requests_html import HTMLSession
import jsonpath

session = HTMLSession()

url = 'https://careers.tencent.com/tencentcareer/api/post/Query?timestamp=1722413528913&countryId=&cityId=&bgIds=&productId=&categoryId=&parentCategoryId=&attrId=&keyword=&pageIndex=1&pageSize=10&language=zh-cn&area=cn'

reponse = session.get(url).json()
print(jsonpath.jsonpath(reponse, '$..RecruitPostName'))
相关推荐
a1117764 小时前
医院挂号预约系统(开源 Fastapi+vue2)
前端·vue.js·python·html5·fastapi
0思必得04 小时前
[Web自动化] Selenium处理iframe和frame
前端·爬虫·python·selenium·自动化·web自动化
摘星编程6 小时前
OpenHarmony + RN:Calendar日期选择功能
python
Yvonne爱编码6 小时前
JAVA数据结构 DAY3-List接口
java·开发语言·windows·python
一方_self6 小时前
了解和使用python的click命令行cli工具
开发语言·python
小芳矶6 小时前
Dify本地docker部署踩坑记录
python·docker·容器
2301_822366357 小时前
使用Scikit-learn构建你的第一个机器学习模型
jvm·数据库·python
小郎君。7 小时前
【无标题】
python
喵手8 小时前
Python爬虫实战:数据治理实战 - 基于规则与模糊匹配的店铺/公司名实体消歧(附CSV导出 + SQLite持久化存储)!
爬虫·python·数据治理·爬虫实战·零基础python爬虫教学·规则与模糊匹配·店铺公司名实体消岐
喵手8 小时前
Python爬虫实战:国际电影节入围名单采集与智能分析系统:从数据抓取到获奖预测(附 CSV 导出)!
爬虫·python·爬虫实战·零基础python爬虫教学·采集数据csv导出·采集国际电影节入围名单·从数据抓取到获奖预测