def login(account, password): def get_post_key(page): return re.findall(r'"pixivAccount.postKey":"(.*?)"', page)[0] def get_PHPSESSID(res): return re.findall(r"PHPSESSID=(.*?);", res.getheader("Set-Cookie"))[0] def get_device_token(res): return re.findall(r"device_token=(.*?);", res.getheader("Set-Cookie"))[0] res = GET("https://accounts.pixiv.net/login") post_key = get_post_key(res.read().decode("utf-8")) PHPSESSID = get_PHPSESSID(res) url = "https://accounts.pixiv.net/api/login?lang=zh_tw" res = POST( url, headers={"Cookie": f"PHPSESSID={PHPSESSID}"}, data={ "password": password, "pixiv_id": account, "post_key": post_key, }, ) return { "device_token": get_device_token(res), "PHPSESSID": get_PHPSESSID(res) }
def parse_member_id(mid, cookie): def getMemberInfo(mid, content): picNum = int( re.findall(r'<span class="count-badge">(.*?)件</span>', content)[0]) pageNum = math.ceil(picNum / 20) memberName = re.findall(r'class="user-name"title="(.*?)">', content)[0] return MemberInfo(mid, memberName, pageNum, picNum, []) def get_illust_id(content): illust_id_list = re.findall(r'data-type="illust"data-id="(\d+)"d', content) return illust_id_list host = "https://www.pixiv.net" url = f"{host}/member_illust.php?id={mid}&type=all&p=1" res = GET(url, headers={"Cookie": cookie}) info = getMemberInfo(mid, res.read().decode("utf-8")) for i in range(1, info.pageNum + 1): url = f"{host}/member_illust.php?id={mid}&type=all&p={i}" info.illustList.extend( get_illust_id( GET(url, headers={ "Cookie": cookie }).read().decode("utf-8"))) return info
def parse_illust_id(pid): def parseTag(page): return re.findall(r'<meta name="keywords" content="(.*?)">', page)[0] def parseTitle(page): return re.findall(r'userdata"><h1 class="title">(.*)</h1>', page)[0] def parseAuthor(page): return re.findall(r'<a href="member.php.*>(.*?)</a></h2>', page)[0] def parseDate(pid, page): m = re.sub( r'.*(?:class="img-container"><a.*?><img src="(.*?)"|class="sensored"><img src="(.*?)").*', r"\1", page, ) return re.sub(r"(?s).*/img/(.*)/" + pid + ".*", r"\1", m) host = "https://www.pixiv.net" url = f"{host}/member_illust.php?mode=medium&illust_id={pid}" res = GET(url).read().decode("utf-8") date = parseDate(pid, res) title = parseTitle(res) tag = parseTag(res) author = parseAuthor(res) return IllustInfo(pid, author, title, tag, date, [])
def getImg(url): return GET(url, headers={"referer": url}).read()