Last active
April 28, 2022 11:05
-
-
Save PC-CNT/844e6377bc55ce0d24d72580fea037de to your computer and use it in GitHub Desktop.
パケ画像を自動で全部落とすやつ (https://psxdatacenter.com/ntsc-j_list.html)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from bs4 import BeautifulSoup | |
| import requests | |
| import urllib | |
| import re | |
| import os | |
| import unicodedata | |
| def _path_executable_kai(moji: str) -> str: | |
| moji = moji.replace("/", "/") | |
| moji = moji.replace("\\", "\") | |
| moji = moji.replace("?", "?") | |
| moji = moji.replace("\n", "_") | |
| moji = moji.replace(":", ":") | |
| moji = moji.replace("\"", "”") | |
| moji = moji.replace("<", "<") | |
| moji = moji.replace(">", ">") | |
| moji = moji.replace("|", "|") | |
| moji = moji.replace("*", "*") | |
| moji = moji.replace("\r", "") | |
| moji = moji.replace("\t", "") | |
| moji = moji.replace("\xa0", "") | |
| return moji | |
| def main(): | |
| #! ※注意 requestsが<frame>に対応していないっぽいのでjlist.htmlを直で叩くようにした | |
| #? root_page = requests.get(r"https://psxdatacenter.com/ntsc-j_list.html") | |
| root_page = requests.get(r"https://psxdatacenter.com/jlist.html") | |
| root_image = r"https://psxdatacenter.com/images/covers/" | |
| soup = BeautifulSoup(root_page.text, "html.parser") | |
| # print(soup.prettify()) | |
| os.makedirs("PS1_covers", exist_ok=True) | |
| os.chdir("PS1_covers") | |
| for table in soup.select("table[class='sectiontable']"): | |
| for tr in table.select("tr"): | |
| if tr.select_one("a[target='jlist']") is not None: | |
| _img_url = urllib.parse.urljoin(root_image, re.sub(r"html$", "jpg", re.sub(r"games/", "", tr.select_one("a[target='jlist']").get("href")))) | |
| print(_img_url) | |
| _img = requests.get(_img_url) | |
| _img_name = (_img_url.split("/")[-1][:-4] + "__(" + | |
| re.sub("^ ", "", _path_executable_kai(unicodedata.normalize("NFKD", (tr.select_one("td[class='col3']").get_text())))) + ")" + ".jpg") | |
| print(_img_name) | |
| if _img.status_code == 200: | |
| with open(_img_name, "wb") as f: | |
| f.write(_img.content) | |
| else: | |
| with open(_img_name, "wb") as f: | |
| f.write(requests.get("https://psxdatacenter.com/images/covers/none.jpg").content) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment