|
| 1 | +import requests |
| 2 | +import time |
| 3 | +import json |
| 4 | +import re |
| 5 | + |
| 6 | +header = { |
| 7 | + 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36' |
| 8 | +} |
| 9 | + |
| 10 | +def get_list(): |
| 11 | + |
| 12 | + try: |
| 13 | + url = 'https://bcy.net/apiv3/common/circleFeed?circle_id=492&since='+str(int(time.time()))+'.000000&sort_type=2&grid_type=10' |
| 14 | + response = requests.get(url,headers= header) |
| 15 | + response.raise_for_status() |
| 16 | + #转码 |
| 17 | + response.encoding = 'utf-8' |
| 18 | + return response.text |
| 19 | + except: |
| 20 | + print("Failed!") |
| 21 | + |
| 22 | +def parse_list(data): |
| 23 | + item_ids = [] |
| 24 | + json_data = json.loads(data) |
| 25 | + for item in json_data['data']['items']: |
| 26 | + item_ids.append(item['item_detail']['item_id']) |
| 27 | + return item_ids |
| 28 | + |
| 29 | +def get_item(item_ids): |
| 30 | + intercepts = [] |
| 31 | + for id in item_ids: |
| 32 | + url = 'https://bcy.net/item/detail/'+ str(id) + '?_source_page=hashtag' |
| 33 | + response = requests.get(url, headers = header) |
| 34 | + response.encoding = 'utf-8' |
| 35 | + text = response.text |
| 36 | + intercept = text[text.index('JSON.parse("') + len('JSON.parse("'): text.index('");')].replace(r'\"',r'"') |
| 37 | + intercepts.append(intercept) |
| 38 | + return intercepts |
| 39 | + |
| 40 | +def download(intercepts): |
| 41 | + for i in intercepts: |
| 42 | + # json_data = json.loads(i) |
| 43 | + pattern = re.compile('"multi":\[{"path":"(.*?)","type"') |
| 44 | + pattern_item_id = re.compile('"post_data":{"item_id":"(.*?)","uid"') |
| 45 | + b = pattern.findall(i) |
| 46 | + item_id = pattern_item_id.findall(i)[0] |
| 47 | + index = 0 |
| 48 | + for url in b: |
| 49 | + index = index + 1 |
| 50 | + content = re.sub(r'(\\u[a-zA-Z0-9]{4})',lambda x:x.group(1).encode("utf-8").decode("unicode-escape"),url) |
| 51 | + response = requests.get(content.replace('\\','')) |
| 52 | + with open('D:\\bcy\\' + str(item_id) + str(index) + '.png', 'wb') as f: |
| 53 | + f.write(response.content) |
| 54 | + |
| 55 | +if __name__ == '__main__': |
| 56 | + data = get_list() |
| 57 | + item_ids = parse_list(data) |
| 58 | + intercepts = get_item(item_ids) |
| 59 | + download(intercepts) |
| 60 | + |
0 commit comments