itchat接口使用示例
有關(guān)itchat接口的知識(shí),小編是初步學(xué)習(xí),這里先給大家分享一段代碼用法示例。
sudo pip3 install itchat
今天用了下itchat接口,從url=”https://lvyou.baidu.com/”上爬了數(shù)據(jù),可以根據(jù)對方發(fā)的城市拼音比如qingdao自動(dòng)回復(fù)這個(gè)城市的旅游信息。
有很多地方還沒搞明白,但是程序照著數(shù)據(jù)分析那個(gè)公眾號(hào)的一篇文章敲得,是可以運(yùn)行了。具體的代碼不到五十行:
#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()
總結(jié)
以上就是本文關(guān)于itchat接口使用示例的全部內(nèi)容,希望對大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站:python實(shí)現(xiàn)微信接口(itchat)詳細(xì)介紹、基于Python和Scikit-Learn的機(jī)器學(xué)習(xí)探索等,有什么問題可以隨時(shí)留言,小編會(huì)及時(shí)回復(fù)大家的。感謝朋友們對本站的支持!
相關(guān)文章
Python 列表(List)的底層實(shí)現(xiàn)原理分析
這篇文章主要介紹了Python 列表(List)的底層實(shí)現(xiàn)原理分析,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-03-03
Python數(shù)據(jù)處理的三個(gè)實(shí)用技巧分享
數(shù)據(jù)處理無所不在,掌握常用技巧,事半功倍。這篇文章將使用Pandas開展數(shù)據(jù)處理分析,總結(jié)其中常用、好用的數(shù)據(jù)分析技巧,感興趣的可以學(xué)習(xí)一下2022-04-04
Python 使用xlwt模塊將多行多列數(shù)據(jù)循環(huán)寫入excel文檔的操作
這篇文章主要介紹了Python 使用xlwt模塊將多行多列數(shù)據(jù)循環(huán)寫入excel文檔的操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-11-11
Python實(shí)戰(zhàn)基礎(chǔ)之Pandas統(tǒng)計(jì)某個(gè)數(shù)據(jù)列的空值個(gè)數(shù)
我們在處理數(shù)據(jù)的時(shí)候,經(jīng)常需要檢查數(shù)據(jù)的質(zhì)量,也需要知道出問題的數(shù)據(jù)在哪個(gè)位置,下面這篇文章主要給大家介紹了關(guān)于Python實(shí)戰(zhàn)基礎(chǔ)之利用Pandas統(tǒng)計(jì)某個(gè)數(shù)據(jù)列空值個(gè)數(shù)的相關(guān)資料,需要的朋友可以參考下2022-08-08
對python中執(zhí)行DOS命令的3種方法總結(jié)
今天小編就為大家分享一篇對python中執(zhí)行DOS命令的3種方法總結(jié),具有很好的參考價(jià)值,希望對大家有所幫助一起。一起跟隨小編過來看看吧2018-05-05

