itchat接口使用示例

yipeiwu_com5年前Python基础

有关itchat接口的知识,小编是初步学习,这里先给大家分享一段代码用法示例。

sudo pip3 install itchat

今天用了下itchat接口,从url=”https://lvyou.baidu.com/”上爬了数据,可以根据对方发的城市拼音比如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接口使用示例的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站:python实现微信接口(itchat)详细介绍基于Python和Scikit-Learn的机器学习探索等,有什么问题可以随时留言,小编会及时回复大家的。感谢朋友们对本站的支持!

相关文章

浅谈django三种缓存模式的使用及注意点

浅谈django三种缓存模式的使用及注意点

django是动态网页,一般来说需要实时的生成访问的页面,展示给访问者,这样,内容可以随时变化,也就说请求到达视图函数之后,然后进行模板渲染,将字符串返回给用户,用户会看到相应的html...

Python使用matplotlib绘制正弦和余弦曲线的方法示例

Python使用matplotlib绘制正弦和余弦曲线的方法示例

本文实例讲述了Python使用matplotlib绘制正弦和余弦曲线的方法。分享给大家供大家参考,具体如下: 一 介绍 关键词:绘图库 官网:http://matplotlib.org/...

python中黄金分割法实现方法

本文实例讲述了python中黄金分割法实现方法。分享给大家供大家参考。具体实现方法如下: ''' a,b = bracket(f,xStart,h) Finds the brac...

Python二次规划和线性规划使用实例

这篇文章主要介绍了Python二次规划和线性规划使用实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 对于二次规划(quadrati...

Python设计模式之中介模式简单示例

Python设计模式之中介模式简单示例

本文实例讲述了Python设计模式之中介模式。分享给大家供大家参考,具体如下: Mediator Pattern:中介模式 中介模式提供了一系列统一的系统接口。此模式也被认为是行为模式,...