[Python] 让python自动给你报告百度新收录了多少页面,并发送到你的邮箱
作者:精品下载站 日期:2020-05-24 00:00:00 浏览:86 分类:编程开发
这两天,百度终于开始收录我的内页了,虽然只是每天收录那么一两条,但是已经让我感觉很不错了(就是这么容易满足),有时候想看看百度收录了我多少页面了,电脑又不在身边,手机操作又不方便,于是就写了这么个python脚本。
功能:
如果有新收录,发送邮件到指定邮箱
每个一小时监控一次。
发送新增页面,和总页面,以及其数量
效果图:
代码:
importsmtplib importtime fromemail.mime.textimportMIMEText importparsel importrequests defget_info(domain): url=f'http://tool.chinaz.com/baidu/?lm=0&wd={domain}&rn=50' headers={ 'User-Agent':'Mozilla/5.0(WindowsNT10.0;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/81.0.4044.138Safari/537.36', } html=requests.get(url=url,headers=headers).text html=parsel.Selector(html) titles=html.xpath("//a[@class='col-blue02']/text()").extract() urls=html.xpath("//a[@class='col-blue02'][email protected]").extract() pages=html.xpath("//a[@class='item'][last()]/text()").extract() try: nums=int(html.xpath("//span[@class='col-blue02'][2]/a/text()").extract()[0]) ifpages: pages=int(pages[0])*10 else: pages=0 ifpages==0: return{ 'titles':titles, 'urls':urls, 'nums':nums } else: all_title=[] all_urls=[] foriinrange(0,pages,10): url=f'http://tool.chinaz.com/baidu/?pn={i}&wd={domain}&rn=10' html=requests.get(url=url,headers=headers).text html=parsel.Selector(html) print(i) all_title.extend(html.xpath("//a[@class='col-blue02']/text()").extract()) all_urls.extend(html.xpath("//a[@class='col-blue02'][email protected]").extract()) return{ 'titles':all_title, 'urls':all_urls, 'nums':nums } except: print("此网站被屏蔽!!!") defsend_mail(infomation,old_nums,old_titles,recever): newnums=infomation['nums'] titles=infomation['titles'] urls=infomation['urls'] new_contents='' ifinfomation['nums']>old_nums: foriinrange(len(titles)): iftitles[i]notinold_titles: new_contents+=f'{titles[i]} {urls[i]} ' mail_content=f'老大,截至{time.strftime("%Y年%m月%d日%H:%M:%S",time.localtime())} 百度新收录:{newnums-old_nums}条 总计收录:{newnums}条 新收录信息如下:' mail_content+=new_contents mail_content+='目前收录如下: ' #By:www.lanol.cn #autor:Lan foriinrange(len(titles)): mail_content+=f'{titles[i]} {urls[i]} ' try: content=MIMEText(mail_content,'plain','utf-8') reveivers=f"{recever}" content['To']=reveivers#设置邮件的接收者,多个接收者之间用逗号隔开 content['From']=str("[email protected]")#邮件的发送者,最好写成str("这里填发送者"),不然可能会出现乱码 content['Subject']=f"老大,你的网站又被百度收录啦!!!{time.strftime('%Y年%m月%d日%H:%M:%S',time.localtime())}"#邮件的主题 smtp_server=smtplib.SMTP_SSL("smtp.exmail.qq.com",465) smtp_server.login("{发送邮箱}","{邮箱密码}") smtp_server.sendmail("[email protected]",[recever],content.as_string()) smtp_server.quit() exceptExceptionase: print(str(e)) exceptsmtplib.SMTPException: print("Error:无法发送邮件") return{ 'newnums':newnums, 'titles':titles, 'urls':urls } if__name__=='__main__': domain=input("请输入你要监控的网址(如:www.lanol.cn,不需要加https这些):") reveiver=input("请输入收信邮箱(如:[email protected]):") nums=0 titles=[] urls=[] whileTrue: new_infomation=send_mail(get_info(domain),nums,titles,reveiver) nums=new_infomation['newnums'] titles=new_infomation['titles'] urls=new_infomation['urls'] print(f'{time.strftime("%Y年%m月%d日%H:%M:%S",time.localtime())}检查成功') time.sleep(3600)
哈哈,刚刚发现个Bug,一个小时之后不能再发送,已经修复了,可以重新下载一下
成品下载地址:
猜你还喜欢
- 03-29 [编程相关] Winform窗体圆角以及描边完美解决方案
- 03-29 [前端问题] has been blocked by CORS policy跨域问题解决
- 03-29 [编程相关] GitHub Actions 入门教程
- 03-29 [编程探讨] CSS Grid 网格布局教程
- 10-12 [编程相关] python实现文件夹所有文件编码从GBK转为UTF8
- 10-11 [编程算法] opencv之霍夫变换:圆
- 10-11 [编程算法] OpenCV Camshift算法+目标跟踪源码
- 10-11 [Python] python 创建 Telnet 客户端
- 10-11 [编程相关] Python 基于 Yolov8 + CPU 实现物体检测
- 03-15 [脚本工具] 使用go语言开发自动化脚本 - 一键定场、抢购、预约、捡漏
- 01-08 [编程技术] 秒杀面试官系列 - Redis zset底层是怎么实现的
- 01-05 [编程技术] 《Redis设计与实现》pdf
取消回复欢迎 你 发表评论:
- 精品推荐!
-
- 最新文章
- 热门文章
- 热评文章
[短剧] 2025年06月03日 精选+付费短剧推荐25部
[软件合集] 25年6月3日 精选软件44个
[短剧合集] 2025年06月2日 精选+付费短剧推荐39部
[软件合集] 25年6月2日 精选软件18个
[软件合集] 25年6月1日 精选软件15个
[短剧合集] 2025年06月1日 精选+付费短剧推荐59部
[短剧] 2025年05月31日 精选+付费短剧推荐58部
[软件合集] 25年5月31日 精选软件66个
[电影] 黄沙漫天(2025) 4K.EDRMAX.杜比全景声 / 4K杜比视界/杜比全景声
[风口福利] 短视频红利新风口!炬焰创作者平台重磅激励来袭
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电视剧] 欢乐颂.5部全 (2016-2024)
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[影视] 【稀有资源】香港老片 艺坛照妖镜之96应召名册 (1996)
[剧集] 神经风云(2023)(完结).4K
[剧集] [BT] [TVB] [黑夜彩虹(2003)] [全21集] [粤语中字] [TV-RMVB]
[资源] B站充电视频合集,包含多位重量级up主,全是大佬真金白银买来的~【99GB】
[影视] 内地绝版高清录像带 [mpg]
[书籍] 古今奇书禁书三教九流资料大合集 猎奇必备珍藏资源PDF版 1.14G
[美图] 2W美女个美女小姐姐,饱眼福
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电影] 美国队长4 4K原盘REMUX 杜比视界 内封简繁英双语字幕 49G
[电影] 死神来了(1-6)大合集!
[软件合集] 25年05月13日 精选软件16个
[精品软件] 25年05月15日 精选软件18个
[绝版资源] 南与北 第1-2季 合集 North and South (1985) /美国/豆瓣: 8.8[1080P][中文字幕]
[软件] 25年05月14日 精选软件57个
[短剧] 2025年05月14日 精选+付费短剧推荐39部
[短剧] 2025年05月15日 精选+付费短剧推荐36部
- 最新评论
-
- 热门tag