栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用Greasemonkey和jQuery从页面拦截JSON / AJAX数据并进行处理

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用Greasemonkey和jQuery从页面拦截JSON / AJAX数据并进行处理

由于目标页面使用jQuery,因此您可以使用轻松监听JSON数据

ajaxSuccess()

然后问题就变成了将数据从页面的作用域中移到GM沙箱中……这可以通过将数据放入特殊的页面节点中来完成。

综上所述,以下内容将帮助您入门:

将近4年后更新:
由于Firefox和Greasemonkey的许多更改,下面的代码现在已过时。由于缺乏兴趣,而且由于它不是大多数RL任务的最佳方法,因此我不打算对其进行重新设计。在大多数情况下;最强大,最便携式和最可靠的方法仍然是智能轮询。

// ==Userscript==// @name _Fun with JSON// @include         http://www.trada.net/*// @require         http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js// ==/Userscript==//--- Create a cell for transmitting the date from page scope to GM scope.$('body'). prepend ('<div id="LatestJSON_Data"></div>');var J_DataCell          = $('#LatestJSON_Data');//--- Evesdrop on the page's AJAX calls and paste the data into our special div.unsafeWindow.$('body').ajaxSuccess (    function (event, requestData)    {        J_DataCell.text (requestData.responseText);    });//--- Listen for changes to the special div and parse the data.J_DataCell.bind ('DOMSubtreeModified', ParseJSON_Data);function ParseJSON_Data (){    //--- Get the latest data from the special cell and parse it.    var myJson   = J_DataCell.text ();    var jsonObj  = $.parseJSON (myJson);    //--- The JSON should return a 2-D array, named "d".    var AuctionDataArray    = jsonObj.d;    //--- Loop over each row in the array.    $.each (        AuctionDataArray,        function (rowIndex, singleAuctionData) { //--- Print the 7th column. console.log ('Row: ' + (parseInt (rowIndex) + 1) + ' Column: 7  Value: ' + singleAuctionData[6]);        }    );}//--- Format our special cell with CSS.  Add "visibility: hidden;" or "display: none;", if desired.GM_addStyle ( (<><![CDATA[    #LatestJSON_Data    {        background:         gold;        border:  3px ridge #0000DD;        font-size:          10px;        margin:  0 2em;        padding: 1ex 1em;        width:   94%;        opacity: 0.8;        overflow:hidden;        z-index: 666;        position:absolute;        color:   black;    }]]></>).toString () );

请注意,问题的建议可能会违反网站的 _服务条款_和/或网站可能会采取对策。(他们已经混淆了他们的JS。)



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/406701.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号