爬虫: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'))
相关推荐
单片机学习之路21 小时前
【Python】输入input函数
开发语言·python
不屈的铝合金21 小时前
Python入门:输入输出(I/O)指南
windows·python·i/o·input·print·输入输出
lifallen21 小时前
Flink Agent 与 Checkpoint:主循环闭环与 Mailbox 事件驱动模型
java·大数据·人工智能·python·语言模型·flink
平安的平安21 小时前
Python 构建AI多智能体系统:让三个 AI 协作完成复杂任务
开发语言·人工智能·python
曲幽21 小时前
FastAPI + Vue 前后端分离实战:我的项目结构“避坑指南”
python·vue·fastapi·web·vite·proxy·cors·env
Kapaseker21 小时前
Python 提速 — 惰性导入
python
杜子不疼.21 小时前
Python + Ollama 本地跑大模型:零成本打造私有 AI 助手
开发语言·c++·人工智能·python
李昊哲小课21 小时前
pip缓存配置
python·缓存·pip
belldeep21 小时前
python:介绍 UV 安装,如何使用 UV 安装配置 OpenHarness
windows·python·环境变量·uv
理想三旬21 小时前
Numpy 数据库
python·机器学习·numpy