需求,监控微博的发布的言论,若是包含有关键字,则报警。 jquery
固然,以上的工做人是彻底能够 打开浏览器,登录微博,而后查看。不过要实现自动化。 web
方法不少,我试了一种简单的方法,相似12306抢票插件。 经过chrome脚本。来获取页面元素,并通知用户。 ajax
// ==UserScript== // @name crowler For Firefox&Chrome // @namespace // @author Bryan Yang // @developer Bryan Yang // @contributor // @description just try to change the background of baidu // @match http://1.t.qq.com/search/* // @require http://lib.sinaapp.com/js/jquery/1.8.3/jquery.min.js // @icon // @run-at document-idle // @version 1.0.0 // @updateURL C:\Users\yanggaofei\Desktop\js // @supportURL // @homepage // @contributionURL // @contributionAmount ¥0.01 // ==/UserScript== //=======START======= function addJQuery(callback) { var script = document.createElement("script"); script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"); script.addEventListener('load', function() { var sc = document.createElement("script"); sc.textContent = "(" + callback.toString() + ")();"; document.body.appendChild(sc); }, false); document.body.appendChild(script); } // // the guts of this userscript function main() { console.log('requestPermission'); window.webkitNotifications.requestPermission(); $('div.sch_btn').append("<button onclick='window.webkitNotifications.requestPermission();'>"+ '开启通知'+"</button>"); window.setInterval(function (){ var text = []; var talklist = document.getElementById('talkList'); console.log('main'); var li = $(talklist).find('li')[0]; var auther = $(li).find('div.userPic a'); var title = auther.attr('title'); text.push(title); var content = $($(li).find('div.msgCnt')[0]).text(); text.push(content); var pub = $($(li).find('div.pubInfo')[0]); var left = pub.find('span.left a'); var time = $(left[0]).attr('title'); text.push(time); var au = $(left[1]).attr('title'); text.push(au); if(window.webkitNotifications.checkPermission()==0){ console.log('createNotification...') //createNotification('腾讯微博提醒',text.join(',')); var showSec = 10000; var icon = "http://d.lanrentuku.com/down/png/1306/sevenesque/messages.png"; var popup = window.webkitNotifications.createNotification(icon, '腾讯微博提醒', text.join(',')); popup.ondisplay = function(event) { setTimeout(function() { event.currentTarget.cancel(); }, showSec); } popup.show(); } //alert(text.join('|')); console.log(text.join('|')); },10*1000); // window.setInterval(function(){ // location.reload(); // },1000*1) } function createNotification(title,body){ var showSec = 10000; var icon = "http://d.lanrentuku.com/down/png/1306/sevenesque/messages.png"; var popup = window.webkitNotifications.createNotification(icon, title, body); popup.tag = tab; popup.ondisplay = function(event) { setTimeout(function() { event.currentTarget.cancel(); }, showSec); } popup.show(); } // load jQuery and execute the main function addJQuery(main);
距离最终目标尚未完成,不过大致思路就这样,我电脑测试能收到通知了。后期能够经过控制页面刷新,并经过jsonp将结构化数据提交到本身的服务器,存到数据库。 还能够加上关键字,来过滤信息。 还可已经言论发送给本身的服务器,服务器进行文本倾向性分析后,返回给浏览器。 chrome