One-click download of Yuanshen’s official website comics with Python, as a gift to those who also like Yuanshen

Hi everyone, hello! I am a cheese who loves to touch fish ❤

I really love playing Yuanshin hahahahahahahahaha

Then I found out that there are comics on its official website

but i'm lazy

I like one-click download~

insert image description here


required modules

import requests
import re

insert image description here

masquerade browser

headers = {
    
    
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.0.0 Safari/537.36'
}

send request

response = requests.get(url=url, headers=headers)
### 提取ID
img_id_list = re.findall('"(\d+)","第.*?话', response.text)

for loop

for img_id in img_id_list:

Details page link

link = f'https://ys.mihoyo.com/main/manga/detail/{
      
      img_id}?mute=1'

Send a request for a detail page link

html_data = requests.get(url=link, headers=headers).text
print(html_data)

Extract image link

img_list = re.findall('<img .*?src="(.*?)"', html_data)
title = re.findall('false,"(.*?)",', html_data)[0]

for loop

num = 1
for img in img_list:

Get image data

img_content = requests.get(img).content
with open('img\\' + title + str(num) + '.jpg', mode='wb') as f:
    f.write(img_content)
    num += 1
print(img)

Show results

insert image description here

insert image description here

insert image description here


Guess you like

Origin blog.csdn.net/m0_74872863/article/details/130171291