直接上代码
# -*- encoding=utf-8 -*-
import hashlib, os, time, requests, random
def get_signature(url, cookies):
sign = os.popen('node ./_signature.js {url} {cookies}'.format(url='"' + url + '"', cookies='"' + cookies + '"')).read()
return "&_signature=" + sign
def GetData():
headers = {
'authority': 'www.toutiao.com',
'sec-ch-ua': 'Google',
'accept': 'application/json, text/plain, */*',
'sec-ch-ua-mobile': '?0',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36',
'sec-fetch-site': 'same-origin',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'referer': 'https://www.toutiao.com/',
'accept-language': 'zh-CN,zh;q=0.9',
'cookie': 'tt_webid=6940593378384299527; ttcid=a59694572e004de09a85a0e72cb9742c90; s_v_web_id=verify_kmdegafs_Cgx7fHyc_DgJo_4UV0_9vhG_xXnoMIbpjBFh; csrftoken=2d2364a073aa953081e1f08fc55d8470; tt_webid=6940593378384299527; MONITOR_WEB_ID=6d7cd5f8-3100-4e43-8579-f599253c048a; tt_scid=AR2ihcP5qDYcrDEw.AXhavTLnUUBPM7JDst3G5JeUPZVG4UQKRShLXp3JI7y5Tr230d4',
}
base_url = 'https://www.toutiao.com'
# if max_behot_time == 0:
# param = '/api/pc/feed/?min_behot_time=0&category=news_hot&utm_source=toutiao&widen=1&tadrequire=true'
# else:
# param = '/api/pc/feed/?max_behot_time={}&category=news_hot&utm_source=toutiao&widen=1&tadrequire=true'.format(
# max_behot_time)
param = f'/c/user/followed/?user_token=MS4wLjABAAAAcYkDGs4uWW_nvdmwB6tbzpI3q0UylFEoHQKk69UW4aQ&cursor={时间戳}&count=20' #用户页面 根据自身需求修改
sign_url = base_url + "/toutiao" + param
signature = get_signature(sign_url, headers["cookie"]).replace('\n', '')
path = param + signature
headers['path'] = path
req_url = base_url + param + signature
print(req_url)
response = requests.get(url=req_url, headers=headers)
print(response.text)
if __name__ == '__main__':
GetData()
```javascript
var glb;
var window = global;
window.document = {
referrer: "https://www.toutiao.com/"};
window.location = {
// hash: "",
host: "www.toutiao.com",
hostname: "www.toutiao.com",
href: "https://www.toutiao.com",
origin: "https://www.toutiao.com",
pathname: "/",
port: "",
protocol: "https:",
search: ""
};
window.navigator = {
appCodeName: "Mozilla",
appName: "Netscape",
appVersion: "5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36",
cookieEnabled: true,
deviceMemory: 8,
doNotTrack: null,
hardwareConcurrency: 4,
language: "zh-CN",
languages: ["zh-CN", "zh"],
maxTouchPoints: 0,
onLine: true,
platform: "Win32",
product: "Gecko",
productSub: "20030107",
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36",
vendor: "Google Inc.",
vendorSub: "",
};
window._$jsvmprt = function(b, e, f) {
function a() {
if ("undefined" == typeof Reflect || !Reflect.construct)
return !1;
if (Reflect.construct.sham)
return !1;
if ("function" == typeof Proxy)
return !0;
try {
return Date.prototype.toString.call(Reflect.construct(Date, [], (function() {
}
))),
!0
} catch (b) {
return !1
}
}
function d(b, e, f) {
return (d = a() ? Reflect.construct : function(b, e, f) {
var a = [null];
a.push.apply(a, e);
var d = new (Function.bind.apply(b, a));
return f && c(d, f.prototype),
d
}
).apply(null, arguments)
}
function c(b, e) {
return (c = Object.setPrototypeOf || function(b, e) {
return b.__proto__ = e,
b
}
)(b, e)
}
function n(b) {
return function(b) {
if (Array.isArray(b)) {
for (var e = 0, f = new Array(b.length); e < b.length; e++)
f[e] = b[e];
return f
}
}(b) || function(b) {
if (Symbol.iterator in Object(b) || "[object Arguments]" === Object.prototype.toString.call(b))
return Array.from(b)
}(b) || function() {
throw new TypeError("Invalid attempt to spread non-iterable instance")
}()
}
for (var i = [], r = 0, t = [], o = 0, l = function(b, e) {
var f = b[e++]
, a = b[e]
, d = parseInt("" + f + a, 16);
if (d >> 7 == 0)
return [1, d];
if (d >> 6 == 2) {
var c = parseInt("" + b[++e] + b[++e], 16);
return d &= 63,
[2, c = (d <<= 8) + c]
}
if (d >> 6 == 3) {
var n = parseInt("" + b[++e] + b[++e], 16)
, i = parseInt("" + b[++e] + b[++e], 16);
return d &= 63,
[3, i = (d <<= 16) + (n <<= 8) + i]
}
}, u = function(b, e) {
var f = parseInt("" + b[e] + b[e + 1], 16);
return f = f > 127 ? -256 + f : f
}, s = function(b, e) {
var f = parseInt("" + b[e] + b[e + 1] + b[e + 2] + b[e + 3], 16);
return f = f > 32767 ? -65536 + f : f
}, p = function(b, e) {
var f = parseInt("" + b[e] + b[e + 1] + b[e + 2] + b[e + 3] + b[e + 4] + b[e + 5] + b[e + 6] + b[e + 7], 16);
return f = f > 2147483647 ? 0 + f : f
}, y = function(b, e) {
return parseInt("" + b[e] + b[e + 1], 16)
}, v = function(b, e) {
return parseInt("" + b[e] + b[e + 1] + b[e + 2] + b[e + 3], 16)
}, g = g || this || window, h = Object.keys || function(b) {
var e = {
}
, f = 0;
for (var a in b)
e[f++] = a;
return e.length = f,
e
}
, m = (b.length,
0), I = "", C = m; C < m + 16; C++) {
var q = "" + b[C++] + b[C];
q = parseInt(q, 16),
I += String.fromCharCode(q)
}
if ("HNOJ@?RC" != I)
throw new Error("error magic number " + I);
m += 16;
parseInt("" + b[m] + b[m + 1], 16);
m += 8,
r = 0;
for (var w = 0; w < 4; w++) {
var S = m + 2 * w
, R = "" + b[S++] + b[S]
, x = parseInt(R, 16);
r += (3 & x) << 2 * w
}
m += 16,
m += 8;
var z = parseInt("" + b[m] + b[m + 1] + b[m + 2] + b[m + 3] + b[m + 4] + b[m + 5] + b[m + 6] + b[m + 7], 16)
, O = z
, E = m += 8
, j = v(b, m += z);
j[1];
m += 4,
i = {
p: [],
q: []
};
for (var A = 0; A < j; A++) {
for (var D = l(b, m), T = m += 2 * D[0], $ = i.p.length, P = 0; P < D[1]; P++) {
var U = l(b, T);
i.p.push(U[1]),
T += 2 * U[0]
}
m = T,
i.q.push([$, i.p.length])
}
var _ = {
5: 1,
6: 1,
70: 1,
22: 1,
23: 1,
37: 1,
73: 1
}
, k = {
72: 1
}
, M = {
74: 1
}
, H = {
11: 1,
12: 1,
24: 1,
26: 1,
27: 1,
31: 1
}
, J = {
10: 1
}
, N = {
2: 1,
29: 1,
30: 1,
20: 1
}
, B = []
, W = [];
function F(b, e, f) {
for (var a = e; a < e + f; ) {
var d = y(b, a);
B[a] = d,
a += 2;
k[d] ? (W[a] = u(b, a),
a += 2) : _[d] ? (W[a] = s(b, a),
a += 4) : M[d] ? (W[a] = p(b, a),
a += 8) : H[d] ? (W[a] = y(b, a),
a += 2) : J[d] ? (W[a] = v(b, a),
a += 4) : N[d] && (W[a] = v(b, a),
a += 4)
}
}
return K(b, E, O / 2, [], e, f);
function G(b, e, f, a, c, l, m, I) {
null == l && (l = this);
var C, q, w, S = [], R = 0;
m && (C = m);
var x, z, O = e, E = O + 2 * f;
if (!I)
for (; O < E; ) {
var j = parseInt("" +