|
发表于 2022-6-16 11:35:45
|
显示全部楼层
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36',
'cookie': 'BIDUPSID=45588421F978DE2902A1A47464D72AB3; PSTM=1609986056; BAIDUID=45588421F978DE29E3D21BB7BB5A6873:FG=1; REALTIME_TRANS_SWITCH=1; FANYI_WORD_SWITCH=1; HISTORY_SWITCH=1; SOUND_SPD_SWITCH=1; SOUND_PREFER_SWITCH=1; __yjs_duid=1_e3607a56e43709e2ca3db4147c46396a1612784778582; BAIDUID_BFESS=45588421F978DE29E3D21BB7BB5A6873:FG=1; Hm_lvt_64ecd82404c51e03dc91cb9e8c025574=1614696427; Hm_lpvt_64ecd82404c51e03dc91cb9e8c025574=1614697139; __yjsv5_shitong=1.0_7_253e552513b2cf371866473b2e57fb4e5137_300_1614697145680_59.50.85.17_fe15699c; ab_sr=1.0.0_ZDRiZDU1NjAzNjRkMDUyOWE3ZTg3MWZlMjRhMGE4NzkwYmI3N2ExMzliMjY3MjIxOGIyY2EyMmMxNWQzOWFmY2UyZDZjMGFkYzVjNWZkNGQ1ZWIxMTJmYjZjM2Y0M2M2'
}
url_start = 'https://www.ibswtan.com/17/17023/' # 凡人修仙传
# 创建书签
if '书签.txt' not in os.listdir():
with open('书签.txt', 'w') as f:
f.write('1146042.html') # 第一章
end = ''
while end != 'q':
with open('书签.txt', 'r') as f:
now = f.read()
url = url_start + now
res = requests.get(url=url, headers=headers)
res.encoding = "utf-8" # 解码不行就gbk
soup = bs4.BeautifulSoup(res.text, "html.parser")
title = soup.find_all('h1')
print(f"========== {title[0].text} =============")
targets = soup.find_all("div", id="content")[0]
for i in targets:
if str(i) != '<br/>' and str(i) != '\n':
print(i)
end = input() # 回车下一行,输入q结束,我喜欢一行一行读
if end == 'q':
break
if end == 'q':
break
next_ = soup.find_all('a', text='下一章')
with open('书签.txt', 'w') as f:
f.write(str(next_[1]).split('"')[1])
end = input('回车下一章')
|
|