首页 > 编程语言 >python 某猫投诉加密解析

python 某猫投诉加密解析

时间:2022-11-12 10:03:37浏览次数:45  
标签:加密 python self ts url print 某猫 data page


import hashlib
import json
import random
import time
import requests
sha256 = hashlib.sha256()

'''

某猫投诉

https://jiangsu.tousu.sina.com.cn/



'''


class BlackCatComplaints(object):

def __init__(self):


self.headers = {
'referer': 'https://jiangsu.tousu.sina.com.cn/',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36',
'x-requested-with': 'XMLHttpRequest',
}



def get_url(self, page_num): # 解码URL
c = str(int(time.time() * 1000)) # 13位时间戳
a = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
"l", "m",
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H",
"I", "J",
"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]

h = ''.join(random.choice(a) for i in range(16)) # 随机16个字符
d = '$d6eb7ff91ee257475%' # 默认值
e = '2' # 最新信息为2
u = '10' # 每页数量
page = str(page_num) # 页码
ts = c
rs = h
bb = [d, u, c, e, page, h]
bb.sort()
signature = hashlib.sha256((''.join(bb)).encode('utf-8')).hexdigest()

url = 'https://jiangsu.tousu.sina.com.cn/api/index/feed?ts={}&rs={}&signature={}&callback=jQuery111207497989586833758_{}&type=2&page_size=10&page={}&_={}'.format(

ts, rs, signature, ts, page_num, ts)
self.get_data(ts, url)

def get_data(self, ts, url): # 请求数据

print(url)
response = requests.get(url=url, headers=self.headers)

response = response.text.replace('\/', '')

content = response.encode('utf-8').decode('unicode_escape')# 乱码解码

jQuery = 'try{jQuery111207497989586833758_' + ts + '('

catch = ');}catch(e){};'

replace_data = content.replace(jQuery, '').replace(catch, '').replace('\n', '')

json_data = json.loads(replace_data)

# print(json_data)
#
if json_data['result']['status']['code'] == 0:

self.get_detail(json_data['result']['data'])

else:

print('接口请求失败!!!')



def get_detail(self, data): # 处理数据


for i in data['lists']:

title = i['main']['title']
url = i['main']['url']
timestamp = i['main']['timestamp']
author = i['author']['title']
avatar = i['author']['avatar']
summary = i['main']['summary']

url = 'https://' + url.replace('complaintview','/complaint/view/') + '/'

timeArray = time.localtime(int(timestamp))
time_str = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)

print(title)
print(url)
print(time_str)
print(author)
print(avatar)
print(summary)






if __name__ == '__main__':

back = BlackCatComplaints()
back.get_url(page=1)

标签:加密,python,self,ts,url,print,某猫,data,page
From: https://www.cnblogs.com/huanghaobing/p/16882738.html

相关文章

  • 元进Python(4)---networkx制作我最喜爱55部美剧天体排名
    利用networkx和matplotlib给我最喜爱的55部美剧来个天体排名【最终呈现效果】【代码实现及注释】importnetworkxasnximportmatplotlib.pyplotaspltUSTVNode=['Everybo......
  • python10
    一、创建并打开记录蚂蚁庄园动态的文件print("\n","="*10,"蚂蚁庄园动态","="*10)film=open('message.txt','w')print("\n即将显示……\n")  二、向蚂蚁庄园的动态文......
  • python apscheculer 报错 skipped: maximum number of running instances reached (1
    apscheduler定时任务报错skipped:maximumnumberofrunninginstancesreached(1)原因是默认max_instances最大定时任务是1个,可以通过在add_job中调max_instances增加......
  • Python实验报告——第10章 文件及目录操作
    实验报告实例01:创建并打开记录蚂蚁庄园动态的文件代码如下:print('\n','='*10,'蚂蚁庄园动态','='*10)file=open('message.txt','w')print('\n即将显示……\n')......
  • Python语法糖之赋值表达式
    目录概述语法(海象运算符)为什么需要这个?避免重复写代码赋值表达式写法例子:连续输入命令行避免重复计算赋值表达式写法在推导式中应用例子:字典倒查本博客主要参考为北京大学......
  • Python第十章实验报告
    一、实验对象:《零基础学Python》6道实例和2道实战二、实验环境:IDLEShell3.9.7三、实验目的:学习如何在Python中进行文件和目录的相关操作四、实验过程:实例01创建并......
  • 献芹奏曝-Python面试题-算法-DFS&BFS
    上一篇:献芹奏曝-Python面试题    开篇的话:本文目的是收集和归纳力扣上的算法题,希望用python语言,竭我所能做到思路最清奇、代码最简洁、方法最广泛、性能最高效,了解......
  • Python语法糖之match-case
    目录概述基本语法和语义example1example2进阶用法如果在case写变量名只是为了不写if语句么?本博客主要参考为北京大学陈斌老师的下一站Python概述match-case是python3.1......
  • OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src
    原先一直以为数据集路径错误,调了半天也没用,后来打印图片列表,发现一个隐藏文件在终端运行 ls-a也出现了这个隐藏文件  删除 rm-rf.ipynb_checkpoints之后成功......
  • python中的运算符
    #1.算术运算符print('1.算术运算符')print('+1+2+3=',1+2+3)print('-10-5-1=',10-5-1)print('*2*2*3=',2*2*3)print('/7/2=',7/2)#除法,操......