爬虫: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'))
相关推荐
Humbunklung22 分钟前
全连接层和卷积层
人工智能·python·深度学习·神经网络·机器学习·cnn
q5673152322 分钟前
Java使用Selenium反爬虫优化方案
java·开发语言·分布式·爬虫·selenium
站大爷IP32 分钟前
使用Python时要注意的十大陷阱
python
Keya1 小时前
使用 tinypng 脚本打包为exe 进行压缩图片
前端·python·程序员
Tom Boom1 小时前
Pytest断言全解析:掌握测试验证的核心艺术
自动化测试·python·测试开发·pytest
Jamesvalley1 小时前
【Django】性能优化-普通版
python·性能优化·django
StackOverthink1 小时前
[特殊字符] Altair:用Python说话,让数据自己讲故事!!!
开发语言·python·其他·信息可视化
xbotcoding2 小时前
Scrapeless Crawl:规模化网络数据抓取与爬行解决方案
爬虫
qq_527887872 小时前
ImportError: cannot import name ‘PfeifferConfig‘ from ‘transformers‘【已解决】
linux·开发语言·python
知舟不叙2 小时前
使用OpenCV和Python进行图像掩膜与直方图分析
人工智能·python·opencv·图像掩膜