I wanted to see a lot of pixiv illustrations from Python. There seems to be little Japanese information on pixivpy, so I will leave it as a memo.
Windows10 Python 3.8 pixivpy 3.5.8 : https://github.com/upbit/pixivpy
Prepare pixivpy From the command prompt
pip install pixivpy
Run
tagsearch_pixivpy.py
from pixivpy3 import PixivAPI
from pixivpy3 import AppPixivAPI
import json
import os
from time import sleep
def login(id, password):
api = PixivAPI()
api.login(id, password)
return api
def search_and_save(apilogin, searchtag, min_score, range_num, directory):
api = apilogin
aapi = AppPixivAPI()
saving_dir_path = os.path.join(directory, searchtag)
if not os.path.exists(saving_dir_path):
os.mkdir(saving_dir_path)
for page in range(1, range_num + 1):
json_result = api.search_works(searchtag, page=page, mode='tag')
illust_len = len(json_result.response)
for i in range(0, illust_len):
illust = json_result.response[i]
score = illust.stats.score
if score <= min_score:
continue
else:
print("Cartoon:" + str(illust.page_count) + "page") if illust.is_manga else print("An illustration")
if illust.is_manga:
print(">>> title:", illust.title)
manga_info = api.works(illust.id)
for page_no in range(0, manga_info.response[0].page_count):
page_info = manga_info.response[0].metadata.pages[page_no]
aapi.download(page_info.image_urls.large, path=saving_dir_path)
sleep(1)
else:
print(">>> title:", illust.title)
aapi.download(illust.image_urls.large, path=saving_dir_path)
sleep(1)
def main():
searchtag = "Search tag" #Search tagを入力。半角スペースで分けることで複数タグ検索可能
min_score = 2000 #DL only for illustrations above this score
range_num = 1 #Search up to the page with this value. 30 sheets per 1p
directory = 'Destination directory' #Create a folder with the search tag name under the specified directory and save it there.
apilogin = login("User name", "password") #User nameとpassword入力
search_and_save(apilogin, searchtag, min_score, range_num, directory)
if __name__ == '__main__':
main()
You can search as you like by changing the variables below the main function. It also supports posting in manga format (a format in which one title has multiple illustrations).
--I want to save directly to Google Drive --Pick up the top 20% of the searched illustrations in order of score
-Collect an infinite number of illustrations from pixiv [python] -I wanted to get an infinite number of illustrations from any illustrator from pixiv -Batch DL of pixiv follower's comics and illustrations
All of them were very helpful in their polite articles.
Recommended Posts