import requests
import re
# 抓取网页
def getHtmlText(url):
try:
r = requests.get(url, timeout=30)
r.raise_for_status()
r.encoding = r.apparent_encoding
return r.text
except:
return ""
# 自动回复
# 封装好的装饰器,当接收到的消息是Text,即文字消息
# @itchat.msg_register(['Text', 'Map', 'Card', 'Note', 'Sharing', 'Picture'])
def text_reply(msg):
# 当消息不是由自己发出的时候
# 回复给好友
url = "http://www.tuling123.com/openapi/api?key=[你的key]&info="
url = url + msg
print(url)
html = getHtmlText(url)
message = re.findall(r'\"text\"\:\".*?\"', html)
reply = eval(message[0].split(':')[1])
print(reply)
if __name__ == '__main__':
while True:
talk = input("我说:")
text_reply(talk)
Jason -用python和电脑人进行对话
最新推荐文章于 2023-11-09 18:36:12 发布