itchat接口使用示例
更新時間:2017年10月23日 10:20:39 作者:螢火之森_1
這篇文章主要介紹了itchat接口使用示例,itchat接口的相關知識,這里是一段代碼示例,這里分享給大家,供需要的朋友參考。努力學習中~
有關itchat接口的知識,小編是初步學習,這里先給大家分享一段代碼用法示例。
sudo pip3 install itchat
今天用了下itchat接口,從url=”https://lvyou.baidu.com/”上爬了數據,可以根據對方發(fā)的城市拼音比如qingdao自動回復這個城市的旅游信息。
有很多地方還沒搞明白,但是程序照著數據分析那個公眾號的一篇文章敲得,是可以運行了。具體的代碼不到五十行:
#Coding='utf-8'
from time import ctime
from bs4 import BeautifulSoup
import itchat
import urllib.request
from pandas import Series
itchat.login()
Help="""please input pinyin
such as
巨野--juye
"""
itchat.send(Help,toUserName='filehelper')
@itchat.msg_register(itchat.content.TEXT)
def getcity(msg):
print(msg['Text'])
pinyin=msg["Text"]
results=getTOUR(pinyin)
itchat.send(results,msg["FromUserName"])
def getTOUR(pinyin):
try:
url="https://lvyou.baidu.com/"+pinyin#ba xiamen tihuancheng pinyin
page=urllib.request.urlopen(url)
html=page.read()
soup=BeautifulSoup(html.decode('utf-8'),"html.parser")
name=soup.find("h3",{'class',"title"}).text
grade = soup.find("div", {'class', "main-score"}).text
describe = soup.find("p", {'class', "main-desc-p"}).text
season = soup.find("span", {'class', "main-besttime"}).text
advice = soup.find("span", {'class', "main-dcnt"}).text
output=name+'\n'+grade+'\n'+describe+'\n'+season+'\n'+advice+'*'*25+u'\n推薦:'
except NameError:
output="not found this place,please ensure that your input place is exist"
return output
#sites=soup.find_all('div',{'class','unmis-li'})
if __name__== '__main__':
itchat.run()
總結
以上就是本文關于itchat接口使用示例的全部內容,希望對大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站:python實現微信接口(itchat)詳細介紹、基于Python和Scikit-Learn的機器學習探索等,有什么問題可以隨時留言,小編會及時回復大家的。感謝朋友們對本站的支持!
您可能感興趣的文章:
相關文章
pytorch中關于distributedsampler函數的使用
這篇文章主要介紹了pytorch中關于distributedsampler函數的使用,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-02-02

