python脚本抓取天气信息并发给微信好友
2017-09-29 23:29
981 查看
最近上海天气变化较大,为了提醒家人及亲朋好友注意关注天气,产生了这个想法。
话不多说,直接上代码,我这里选取特定好友发送。
话不多说,直接上代码,我这里选取特定好友发送。
#!/usr/bin/env python # encoding: utf-8 """ @version: ?? @author: heyifei @email:heyifei88@foxmail.com @license: Apac_he Licence @file: sendweathertoone.py @time: 2017/9/2 22:07 """ import requests as req from lxml import etree import itchat # 定义url shanghai_url = "http://www.nmc.cn/publish/forecast/ASH/shang-hai.html" changde_url = "http://www.nmc.cn/publish/forecast/AHN/chang-de.html" chongqing_url = "http://www.nmc.cn/publish/forecast/ACQ/chong-qing.html" # 给特定好友发送 friends = ['@xxxxxxx', '@xxxxxxx', '@xxxxxxx', '@xxxxxxx', '@xxxxxxx', '@xxxxxxx', '@xxxxxxx'] def geturlinfobyxpath(url): '''获取URL页面信息''' kv = {'user-agent': 'Mozilla/5.0'} r = req.get(url, headers=kv) r.raise_for_status() r.encoding = r.apparent_encoding tree = etree.HTML(r.text) nodes = tree.xpath('//div[@class="day"]/div/text()') city = tree.xpath('//title/text()') updatetime = tree.xpath('//div[@class="btitle"]/span/text()') newnode ="".join(nodes).replace("\n", "").replace(" ", "") sms = "来源:xxxx为您抓取中央气象台数据。" sendsms = '%s%s%s%s' % (city, updatetime, newnode, sms) itchat.auto_login(hotReload=True)
#给所有微信好友发送 # friends = itchat.get_friends() for f in friends:
给所有微信好友发送 # username = f.UserName itchat.send_msg(sendsms, toUserName=f) #print(sendsms) if __name__ == '__main__': geturlinfobyxpath(shanghai_url)
相关文章推荐
- python项目:获取微信好友信息(一)抓取微信好友数据
- 利用Python网络爬虫抓取微信好友的签名及其可视化展示
- python类似微信未读信息图片脚本
- Python爬虫抓取携程网机票信息并发邮件通知
- Python 脚本帮你找出微信上删除了你的“好友“
- Python 脚本帮你找出微信上删除了你的“好友“
- Python找出微信上删除你好友的人脚本写法
- python 脚本查看微信把你删除的好友--win系统版
- 用python玩微信(聊天机器人,好友信息统计)
- 黑科技 Python脚本帮你找出微信上删除你好友的人
- python数据分析(1)——获取微信好友的统计信息
- 用python 分析微信好友信息并生成词云
- java 网页版 找出删除你的微信好友(翻译修改自python脚本)
- Python微信好友信息意义及取值分析(基于itchat)
- python3爬虫--抓取天气信息
- 使用python抓取微信好友个性签名并形成词云(itchat;wordcloud)
- python 学习笔记 12 -- 写一个脚本获取城市天气信息
- python练习--天气信息抓取(1)
- Python爬取自己微信好友信息,并制作好友签名词云