漫画柜爬虫测试

本来想用pyexecjs一步到位的,无奈报错ReferenceError: SMH is not defined 就只能这样了

import requests
import re
import lzstring
z = lzstring.LZString()
url = 'https://www.mhgui.com/comic/43543/'
zym = requests.get(url)
zymt = zym.text
dhz0 = re.findall('"display:block">(.*?)class="comment mt10"',zymt)
dhz0=str(dhz0)
dhz = re.findall('<li><a href="(.*?)"\stitle="',dhz0)#每话链接
dhzs = len(dhz)#总话数
x=0
while dhzs>0:
    durl = 'https://www.mhgui.com'+dhz[dhzs-1]
    ym = requests.get(durl)
    ymt = ym.text
    #print(ymt)
    miwen = re.findall("\d\d,\d\d,(.*?)'\[",ymt)
    miwen=''.join(miwen)
    miwen = miwen.replace("'",'')
    jiemi = z.decompressFromBase64(miwen).split('|')
    #print(miwen)
    #print(jiemi)
    ymt1 = ymt.replace("'"+miwen,str(jiemi))
    t1 ='window["\\x65\\x76\\x61\\x6c"]'
    w1 = "'['\\x73\\x70\\x6c\\x69\\x63']('\\"#'('\\x7c
    ymt2 = ymt1.replace(t1,"eval")
    ymt3 = ymt2.replace(w1,'')
    ymt4 = ymt3.replace("x7c')",'')
    #print(ymt4)
    print('\n\n\n')
    ok = re.findall('js"></script><script type="text/javascript">(.*?) </script>',ymt4)
    ok = ''.join(ok)
    ok1 = ok.replace("false","1")
    ok2 = ok1.replace("\s","")
    print("第",x,"话列表")
    print(ok2)
    x+=1
    dhzs-=1
    

将上面输出的内容复制在以下网站解密
js解密
在这里插入图片描述
zd就是刚才解密的字典

from posixpath import basename
import re
import requests
import os

zd = {"bid":43543,"bname":"令和的斑 小姐","bpic":"43543.jpg","cid":623971,"cname":"第01话","files":["1.jpg.webp","2.jpg.webp","3.jpg.webp","4.jpg.webp","6.jpg.webp","7.jpg.webp","8.jpg.webp","9.jpg.webp","10.jpg.webp","11.jpg.webp","12.jpg.webp","13.jpg.webp","14.jpg.webp","15.jpg.webp","16.jpg.webp","999.jpg.webp","12487497l.jpg.webp"],"finished":1,"len":17,"path":"/ps1/z/zc-18973/lhdbxj/第01话/","status":1,"block_cc":"","nextId":624241,"prevId":0,"sl":{"e":1651645945,"m":"hHNSlFc6dyH-JqiqrFHGhg"}}
tu = zd['files']#所有页的文件名
tus = len(zd['files'])#本话总页数
mem = zd['sl']#e码和m码
em = "?e="+str(mem['e'])#e码
mm = "&m="+mem['m']#m码
bname= zd['bname']#漫画名
cname = zd["cname"]#第几话
path = zd['path']#服务器文件路径
x = 0
wj = os.path.exists('d:/manga/%s'%bname)
print(wj)
if wj==0:
    os.makedirs('d:/manga/%s'%bname)
while x<tus:
        head ={
           'Referer': 'https://www.mhgui.com/',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="100", "Google Chrome";v="100"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36'
        }  
        url = 'https://eu.hamreus.com/'+path+tu[x]+em+mm
        tuym = requests.get(url=url,headers=head)
        print(url)
        print(tuym.status_code)
        f=open('d:/manga/%s/%s%s-%s.png'%(bname,bname,cname,x),'wb')
        f.write(tuym.content)
        print(cname,"第",x,"页保存完成")
        x+=1
![在这里插入图片描述](https://img-blog.csdnimg.cn/4854421e04924a16b0242a606809cb39.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5pqX56Kz,size_20,color_FFFFFF,t_70,g_se,x_16)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值