爬虫: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'))
相关推荐
John Song1 小时前
Python创建虚拟环境的方式对比与区别?
开发语言·python
geovindu1 小时前
python: Bridge Pattern
python·设计模式·桥接模式
搞程序的心海1 小时前
Python面试题(一):5个最常见的Python基础问题
开发语言·python
宝贝儿好4 小时前
【强化学习实战】第十一章:Gymnasium库的介绍和使用(1)、出租车游戏代码详解(Sarsa & Q learning)
人工智能·python·深度学习·算法·游戏·机器学习
程序媛一枚~7 小时前
✨✨✨使用Python,OpenCV及图片拼接生成❤️LOVE❤️字样图,每张小图加随机颜色边框,大图加随机大小随机颜色边框
图像处理·python·opencv·numpy·图像拼接
MediaTea7 小时前
Python:collections.Counter 常用函数及应用
开发语言·python
如若1238 小时前
flash-attn 安装失败?从报错到成功的完整排雷指南(CUDA 12.8 + PyTorch 2.7)
人工智能·pytorch·python
007张三丰8 小时前
知乎高赞回答爬虫:从零开始,建立你的专属知识库
爬虫·python·知识库·python爬虫·知乎·高赞回答
李昊哲小课8 小时前
Python json模块完整教程
开发语言·python·json
易醒是好梦8 小时前
Python flask demo
开发语言·python·flask