Copy # 以下是turingAPI的comment方法(beta 0.1):
def comment(self,workId,data):
return self.http.request('POST','https://icodeshequ.youdao.com/api/works/comment',body=('{"id":"'+str(workId)+'","content":"'+str(data)+'"}').encode('utf-8'),headers={'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json;charset=UTF-8',
'Cookie': self.cookie,'User-Agent': self.userAgent})
# 以下是turingIO的comment方法(turingIO 基础版0.5):
def comment(self,urll,datas,isencode="is"):
try:
urll=str(urll)
datas=str(datas)
isencode=str(isencode)
temp=0
if not urll.find("?from=")==-1:
urll=urll[0:urll.find('?from='):1][-32::]
else:
urll=urll[-32::]
datas='{"id":"'+str(urll)+'","content":"'+str(datas)+'"}'
if isencode=="is":
temp=requests.post(url='https://icodeshequ.youdao.com/api/works/comment',data=datas.encode("utf-8"),headers={'Accept': 'application/json, text/plain, */*',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'Connection': 'keep-alive',
'Content-Length': '654',
'Content-type': 'application/json',
'Cookie': self.cookies,
'Host': 'icodeshequ.youdao.com',
'Origin': 'https://icodeshequ.youdao.com',
'Referer': 'https://icodeshequ.youdao.com/work/'+ urll +'?from=home',
'sec-ch-ua': '" Not;A Brand";v="99", "Microsoft Edge";v="103", "Chromium";v="103"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36 Edg/103.0.1264.49})'})
else:
temp=requests.post(url='https://icodeshequ.youdao.com/api/works/comment',data=datas,headers={'Accept': 'application/json, text/plain, */*',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'Connection': 'keep-alive',
'Content-Length': '654',
'Content-type': 'application/json',
'Cookie': self.cookies,
'Host': 'icodeshequ.youdao.com',
'Origin': 'https://icodeshequ.youdao.com',
'Referer': 'https://icodeshequ.youdao.com/work/'+ urll +'?from=home',
'sec-ch-ua': '" Not;A Brand";v="99", "Microsoft Edge";v="103", "Chromium";v="103"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36 Edg/103.0.1264.49})'})
except UnicodeEncodeError:
print("用户"+self.userid+'调用comment时Unicode字符转换错误:发送中文及更多字符必须将isencode参数调为is,否则无法转换至bytes。或者您的参数类型输入错误!')
except:
print("用户"+self.userid+"在使用comment方法时出现未知错误,请检查您的网络是否已连接,或者是您的ip已经被小图灵封禁")
else:
if not str(temp)=='<Response [200]>':
print("用户"+self.userid+"访问异常:"+str(temp)[str(temp).find('[')+1:-2:1])
print(temp.text)
return temp
#turingAPI 胜出