Backend Development 8 min read

Python Script for Scraping and Converting Anime Images from Huashi6

This article explains how to use Python's requests, BeautifulSoup, and Pillow libraries to crawl high‑resolution anime pictures from the Huashi6 website, extract their webp URLs via regex, download them, and convert the images to the more common png format for personal use.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Python Script for Scraping and Converting Anime Images from Huashi6

The tutorial demonstrates a Python program that crawls the popular anime site Huashi6, retrieves high‑definition images, and converts the original webp files to the widely supported png format.

Program Overview – The script imports time , requests , BeautifulSoup from bs4 , os , re , urljoin from urllib.request , and Image from PIL . It creates two directories, girlfriends_webp and girlfriends_png , for storing the raw and converted images.

URL Pattern – A page‑number placeholder URL "https://www.huashi6.com/tags/161?p={}" is used to iterate through multiple tag pages (e.g., pages 1‑20). The domain for image resources is https://img2.huashi6.com .

Image URL Extraction – For each page, the script fetches the HTML with custom headers, sets response.encoding = 'unicode-escape' to expose the embedded JSON, and parses the second <script> element. A regular expression r'"path":"(.*?)"' extracts the relative image paths.

Downloading and Saving – Each relative path is joined with the domain using urljoin . The filename is derived from the URL, saved as .webp in the webp folder, and then converted to .png in the png folder. The download_image function handles HTTP requests, writes the binary content, and calls change_webp2png to perform the conversion with Pillow.

Conversion Logic – change_webp2png opens the downloaded .webp file via Image.open and saves it as .png . If conversion fails, the script retries the download.

Full Code – The article provides the complete source code, including the helper functions analysis , download_image , and change_webp2png , as well as the main loop that iterates over page numbers, extracts URLs, and processes each image.

The guide also includes screenshots of the target website, sample output images, and a brief promotional note for a free Python course, but the core content remains a practical example of web scraping and image format conversion.

web scrapingRequestspillowimage-processingBeautifulSoup
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.