Excited heart, trembling hands, wife you who did not?
(Photo is from the Rice Travel Agency)
On July 21, The Original Gods 2.0 was released. Did you update it?
Update content list:
1. Rice Wife City: Rice wife City is connected to six islands, of which the new islands are only three.
2. Home system update: plants and planting system will be added;
3. New holy relics: three new holy relics of the Rice Wife party;
4, the main characters: yaeghi god son, coral palace xinghai, early pomelo, god in ayanami, Toma, Bal, night palace, five lang.
I was so excited that I could not stand looking at these cosplay beauties when I was visiting the rice tour club. I crawled the cosplay fan picture for everyone all night and saved it! Enjoy together, below we have a look at these beauty, is not the code operation, just give you a practice hand small project!
First, let’s take a look at the renderings:
Project introduction
Development environment: Python3.6
Module (library) : Requests/json/OS/threading
Climb the target: climb the official website of the original god, rice tour society. Bbs.mihoyo.com/ys/home/49 (m swimming club. The original god)
Objective: To crawl the image under the COS zone and save it
In the COS area, the images are sorted by the latest reply column, so the images that are crawled will change with the latest time. When the program runs, it automatically crawls the latest 20 pictures.
1. Import libraries
import requests
import json
import os
import threading
Copy the code
2. Initialize the URL and set the UA proxy (note: the URL here is not the home page, but a secondary page).
class WebSpider(object): def __init__(self): self.url = 'https://bbs-api.mihoyo.com/post/wapi/getForumPostList?forum_id=49' self.headers = { 'User-Agent': 'the Mozilla / 5.0 (Windows NT 10.0; Win64; X64) AppleWebKit/537.36 (KHTML, like Gecko)' 'Chrome/92.0.4515.107 Safari/537.36'}Copy the code
3. Analyze data and store it as a dictionary return
def parse(self): img_dict_data = {} res = requests.get(self.url, headers=self.headers).content.decode('utf-8') res = json.loads(res) res = res['data']['list'] subject_name = [i['post']['subject'] for i in res] cover_url = [i['post']['cover'] for i in res] # print(cover_url, For name, url in zip(subject_name, cover_URL): # print(name, url) img_dict_data[name] = url return img_dict_dataCopy the code
4. Save the picture
def save_img(self, data): for k, v in data.items(): Img_type = v. plit ('/') [1]. The split ('. '). [1] save_path = OS path. The dirname (OS) path) join (__file__)) + '/ img' # pictures of the current directory path if not os.path.exists(save_path): os.mkdir('img') with open(f'img/{k}.{img_type}', 'wb') as f: Img = request.get (v, headers=self.headers).content f.rite (img) print(f'{k}.{img_type}) 'Copy the code
More I will not say, the source code with detailed instructions:
"" crawl" address: https://bbs-api.mihoyo.com/post/wapi/getForumPostList?forum_id=49 getForumPostList: Json data forum_id=49: "" import requests import JSON import OS import threading class WebSpider(object): def __init__(self): self.url = 'https://bbs-api.mihoyo.com/post/wapi/getForumPostList?forum_id=49' self.headers = { 'User-Agent': 'the Mozilla / 5.0 (Windows NT 10.0; Win64; X64) AppleWebKit/537.36 (KHTML, like Gecko) "" Chrome/92.0.4515.107 Safari/537.36"} def parse(self): img_dict_data = {} res = requests.get(self.url, headers=self.headers).content.decode('utf-8') res = json.loads(res) res = res['data']['list'] subject_name = [I ['post']['subject'] for I in res] cover_URL = [I ['post']['cover'] for I in res] # print(cover_URL, For name, url in zip(subject_name, cover_URL): # print(name, url) def save_img(self, data): for k, v in data.items(): Img_type = v. plit ('/') [1]. The split ('. ') [1] # get picture type save_path = OS. The path. The dirname (OS) path) join (__file__)) + '/ img' # If not os.path.exists(save_path): Os.mkdir ('img') with open(f'img/{k}.{img_type}', 'wb') as f: Img = request.get (v, headers=self.headers).content # print(f'{k}.{img_type} -- print(f'{k}. ') def main(self): data = self.parse() self.save_img(data)Copy the code
(The picture is from miyoushe, left yishinli tongren picture, right blogger 仧 Lang cos picture)
What kind of bike do you need with that kind of technology? Benefits have been posted, you can leave your likes before you go!! Source to see the introduction!! Keyword reply “original god”