forked from mokeyjay/Yandere-crawler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYandere.py
46 lines (41 loc) · 1.03 KB
/
Yandere.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import json
import Http
# 基本上是json操作
def get_json(page: int, tag_on, tags: str):
"""
获取列表页的json数据
:param page: 页码
:type page: int
:param tag_on: tag搜索开关
:type tags: str
:return: str
"""
if tag_on:
url = 'https://yande.re/post.json?tags={}&page={}'.format(tags, str(page))
else:
url = 'https://yande.re/post.json?page=' + str(page) #JSON API
json_data = Http.get(url)
if not json_data:
print('请求 ' + url + ' 失败')
exit()
try:
json_data = json_data.decode('utf-8')
except:
print(url + ' 解码失败')
exit(500)
return json_data
def get_li(json_data: str):
"""
获取li数据列表
:param json: json_data数组
:type json_data: str
:return: list
"""
return json.loads(json_data)
def return_json(settings: dict):
"""
:param settings: 配置项,缩进宽度4
:type settings: dict
:return: json
"""
return json.dumps(settings, indent = 4)