123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- import urllib.parse
- import requests
- import config
- DEFAULT_RECOMMENDS_PAGE_SIZE = 18
- RECOMMENDS_PAGE_SIZE = DEFAULT_RECOMMENDS_PAGE_SIZE * 2
- MAX_RECOMMENDS_PAGE_SIZE = 161
- def gen_auth_headers():
- return {
- 'Cookie': f'PHPSESSID={config.SESSION_ID}',
- 'User-Agent': 'Mozilla/5.0'
- }
- def fetch_illust_pages(illust_id):
- url = f'https://www.pixiv.net/ajax/illust/{illust_id}/pages'
- resp = requests.get(url, headers=gen_auth_headers(), proxies=config.PROXIES)
- resp.raise_for_status()
- return resp
- def fetch_illust(illust_id):
- url = f'https://www.pixiv.net/ajax/illust/{illust_id}'
- resp = requests.get(url, headers=gen_auth_headers(), proxies=config.PROXIES)
- resp.raise_for_status()
- return resp
- def fetch_comments(illust_id):
- url = f'https://www.pixiv.net/ajax/illusts/comments/roots?illust_id={illust_id}'
- resp = requests.get(url, proxies=config.PROXIES)
- resp.raise_for_status()
- return resp
- def fetch_user_top(user_id):
- url = f'https://www.pixiv.net/ajax/user/{user_id}/profile/top'
- resp = requests.get(url, headers=gen_auth_headers(), proxies=config.PROXIES)
- resp.raise_for_status()
- return resp
- def fetch_user_all(user_id):
- url = f'https://www.pixiv.net/ajax/user/{user_id}/profile/all'
- resp = requests.get(url, headers=gen_auth_headers(), proxies=config.PROXIES)
- resp.raise_for_status()
- return resp
- def fetch_user_bookmarks(user_id, offset=0, limit=48):
- url = f'https://www.pixiv.net/ajax/user/{user_id}/illusts/bookmarks?offset={offset}&limit={limit}&rest=show&tag='
- resp = requests.get(url, headers=gen_auth_headers(), proxies=config.PROXIES)
- resp.raise_for_status()
- return resp
- def fetch_user_illusts(user_id, illust_ids):
- url = f'https://www.pixiv.net/ajax/user/{user_id}/profile/illusts'
- params = '?work_category=illustManga&is_first_page=0'
- for illust_id in illust_ids:
- params += '&ids[]=' + illust_id
- resp = requests.get(url + params, headers=gen_auth_headers(), proxies=config.PROXIES) # auth and proxy needed?
- resp.raise_for_status()
- return resp
- def fetch_illust_recommends_init(illust_id, limit=RECOMMENDS_PAGE_SIZE):
- url = f'https://www.pixiv.net/ajax/illust/{illust_id}/recommend/init?limit={limit}'
- resp = requests.get(url, headers=gen_auth_headers(), proxies=config.PROXIES)
- resp.raise_for_status()
- return resp
- #def fetch_illust_recommends_next(ids):
- # url = f'https://www.pixiv.net/ajax/illust/recommend/'
- # resp = requests.get(url, headers=gen_auth_headers(), proxies=config.PROXIES) # auth and proxy needed??
- # resp.raise_for_status()
- # return resp
- def fetch_user_banner(user_id):
- resp = requests.get(f'https://embed.pixiv.net/user_profile.php?id={user_id}', proxies=config.PROXIES)
- resp.raise_for_status()
- return resp
- def fetch_search_results(search_term):
- search_term_encoded = urllib.parse.quote(search_term)
- resp = requests.get(f'https://www.pixiv.net/ajax/search/artworks/{search_term_encoded}', headers=gen_auth_headers(), proxies=config.PROXIES)
- resp.raise_for_status()
- return resp
- def fetch_landing_page():
- resp = requests.get(f'https://www.pixiv.net/ajax/top/illust', headers=gen_auth_headers(), proxies=config.PROXIES)
- resp.raise_for_status()
- return resp
|