需求,監控微博的發佈的言論,若是包含有關鍵字,則報警。 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