You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
m123/get_contend.py

61 lines
1.8 KiB

6 months ago
import requests
import json
from lxml import etree
import js2py
import login
USERNAME="td188310339"
PASSWORD="Aa123456"
COOKIE=login(USERNAME,PASSWORD)
HEADERS={
'Cookies':COOKIE
}
BASE_URL='https://www.tadu.com/'
def get_id(num):
text =requests.get(f'{BASE_URL}/book/988681/{num+1}/?isfirstpart=true',headers=HEADERS).text
html=etree.HTML(text)
return html.xpath('//a[@id="paging_left"]/@href')[0].strip().split('/')[-1]
for chapter_num in range (1,101):
js_code = """
function encipher(e) {
var a = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
, t = "="
, o = function(e) {
var o, s = "", i = e.length;
for (o = 0; i - 2 > o; o += 3)
s += a[e.charCodeAt(o) >> 2],
s += a[((3 & e.charCodeAt(o)) << 4) + (e.charCodeAt(o + 1) >> 4)],
s += a[((15 & e.charCodeAt(o + 1)) << 2) + (e.charCodeAt(o + 2) >> 6)],
s += a[63 & e.charCodeAt(o + 2)];
return i % 3 && (o = i - i % 3,
s += a[e.charCodeAt(o) >> 2],
i % 3 == 2 ? (s += a[((3 & e.charCodeAt(o)) << 4) + (e.charCodeAt(o + 1) >> 4)],
s += a[(15 & e.charCodeAt(o + 1)) << 2],
s += t) : (s += a[(3 & e.charCodeAt(o)) << 4],
s += t + t)),
s
};
return o(e)
}
"""
encipher = js2py.eval_js(js_code)
chapter_id = get_id(1)
dataLimit = encipher(chapter_id)
print(dataLimit)
res = requests.get(f'{BASE_URL}getPartContentByCodeTable/988681/{chapter_num},headers=HEADERS)')
text = res.text
text = json.loads(text)
text = text['data']['content']
html = etree.HTML(text)
texts = html.xpath(f'//p[not(constains(@data-limit,"{dataLimit}"))]/text()')
for txt in texts:
print(txt)