import json, urllib.request, re KEY = open('.weread/apikey.txt', encoding='utf-8').read().strip() URL = "https://i.weread.qq.com/api/agent/gateway" def call(api, **kw): body = {"skill_version": "1.0.4", "api_name": api} body.update(kw) req = urllib.request.Request(URL, data=json.dumps(body).encode('utf-8'), headers={"Authorization": "Bearer " + KEY, "Content-Type": "application/json"}) with urllib.request.urlopen(req, timeout=60) as r: return json.loads(r.read().decode('utf-8')) res = call('/book/bestbookmarks', bookId='847310', chapterUid=0) json.dump(res, open('.weread/tmp/best_847310.json', 'w', encoding='utf-8'), ensure_ascii=False) if res.get('upgrade_info'): print('UPGRADE_INFO:', json.dumps(res['upgrade_info'], ensure_ascii=False)) items = res.get('items') or [] print('TOTAL ITEMS:', len(items)) def ok(t): t = (t or '').strip() if len(t) < 8: return False has_cn = bool(re.search(r'[\u4e00-\u9fff]', t)) if not has_cn and len(t) < 20: return False if not has_cn and t[-1] not in '.!?': return False if t[-1] in ',,::((、': return False return True for i, it in enumerate(items[:8]): t = (it.get('markText') or '').strip() print('--- #%d | totalCount=%s | chapter=%s | pass=%s' % ( i+1, it.get('totalCount'), it.get('chapterTitle'), ok(t))) print(repr(t[:220]))