-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathxiaobing.py
147 lines (135 loc) · 4.56 KB
/
xiaobing.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#-*-encoding:utf-8 -*-
# 微软小冰链接:http://kan.msxiaobing.com/V3/Portal?task=yanzhi
import requests
import json
import time
import base64
from bs4 import BeautifulSoup
session = requests.Session()
# 获取参数tid
def getTid():
url = 'http://kan.msxiaobing.com/V3/Portal?task=yanzhi'
req = session.get(url)
soup = BeautifulSoup(req.text,'html.parser')
return soup.select('#xb_log_info input')[0]['value']
# 图片转为Base64
def toBase64(imgUrl):
req = session.get(imgUrl)
return base64.b64encode(req.content)
# 上传Base64加密图片获取图片url
def upload(imgBase64):
url = 'http://kan.msxiaobing.com/Api/Image/UploadBase64'
headers = {
'Host':'kan.msxiaobing.com',
'Origin':'http://kan.msxiaobing.com',
'Referer':'http://kan.msxiaobing.com/V3/Portal?task=yanzhi',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'
}
req = session.post(url=url,headers=headers,data=imgBase64)
json_data = json.loads(req.text)
return json_data['Host'] + json_data['Url']
#### 小冰功能 ####
# 颜值测试
def yanzhi(imgUrl):
tid = getTid()
url = 'http://kan.msxiaobing.com/Api/ImageAnalyze/Process?service=yanzhi&tid='+tid
headers = {
'Host':'kan.msxiaobing.com',
'Origin':'http://kan.msxiaobing.com',
'Referer':'http://kan.msxiaobing.com/V3/Portal?task=yanzhi',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'
}
imgInfo = upload(toBase64(imgUrl))
CreateTime = str(int(time.time()))
data = {
'MsgId':CreateTime+'222',
'CreateTime':CreateTime,
'Content[imageUrl]':imgInfo
}
req = session.post(url=url,headers=headers,data=data)
print(req.text)
# 谁眼中你最美
def beauty(imgUrl):
tid = getTid()
url = 'https://kan.msxiaobing.com/Api/ImageAnalyze/Process?service=beauty&tid='+tid
headers = {
'Host':'kan.msxiaobing.com',
'Origin':'http://kan.msxiaobing.com',
'Referer':'http://kan.msxiaobing.com/V3/Portal?task=beauty',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'
}
imgInfo = upload(toBase64(imgUrl))
CreateTime = str(int(time.time()))
data = {
'MsgId':CreateTime+'039',
'CreateTime':CreateTime,
'Content[imageUrl]':imgInfo
}
req = session.post(url=url,headers=headers,data=data)
print(req.text)
# 查看关系
def guanxi(imgUrl):
tid = getTid()
url = 'https://kan.msxiaobing.com/Api/ImageAnalyze/Process?service=guanxi&tid='+tid
headers = {
'Host':'kan.msxiaobing.com',
'Origin':'http://kan.msxiaobing.com',
'Referer':'http://kan.msxiaobing.com/V3/Portal?task=guanxi',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'
}
imgInfo = upload(toBase64(imgUrl))
CreateTime = str(int(time.time()))
data = {
'MsgId':CreateTime+'039',
'CreateTime':CreateTime,
'Content[imageUrl]':imgInfo
}
req = session.post(url=url,headers=headers,data=data)
print(req.text)
# 谁请客
def qingke(imgUrl):
tid = getTid()
url = 'https://kan.msxiaobing.com/Api/ImageAnalyze/Process?service=qingke&tid='+tid
headers = {
'Host':'kan.msxiaobing.com',
'Origin':'http://kan.msxiaobing.com',
'Referer':'http://kan.msxiaobing.com/V3/Portal?task=qingke',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'
}
imgInfo = upload(toBase64(imgUrl))
CreateTime = str(int(time.time()))
data = {
'MsgId':CreateTime+'039',
'CreateTime':CreateTime,
'Content[imageUrl]':imgInfo
}
req = session.post(url=url,headers=headers,data=data)
print(req.text)
# 诗人小冰
def poem(imgUrl):
tid = getTid()
url = 'https://kan.msxiaobing.com/Api/ImageAnalyze/Process?service=poem&tid='+tid
headers = {
'Host':'kan.msxiaobing.com',
'Origin':'http://kan.msxiaobing.com',
'Referer':'http://kan.msxiaobing.com/V3/Portal?task=poem',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'
}
imgInfo = upload(toBase64(imgUrl))
CreateTime = str(int(time.time()))
data = {
'MsgId':CreateTime+'039',
'CreateTime':CreateTime,
'Content[imageUrl]':imgInfo
}
req = session.post(url=url,headers=headers,data=data)
print(req.text)
def main():
imgUrl = 'https://mediaplatform.msxiaobing.com/image/fetchimage?key=JMG8DUAwYwWliXg8jfwZ1sn-NvROLOBEbXjS9bOo2lI_2wHA74fJYV7zXw'
yanzhi(imgUrl)
# beauty(imgUrl)
# guanxi(imgUrl)
# qingke(imgUrl)
# poem(imgUrl)
if __name__ == '__main__':
main()