用油脂猴子存储或登录数据,以后可以处理 [英] Storing or loggin data with greasemonkey which can be processed later

查看:81
本文介绍了用油脂猴子存储或登录数据,以后可以处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正忙于一个网站,我想为其写一个润滑脂脚本,该脚本记录所有数据或至少某些位置的数据,并将其保存在可与excell互换的文件中.那可能吗?例如说我采用以下数据片段:

I'm curently busy on a site for which i want to write a greasemonkey script that logs all the data, or at least certain postions of it, and saves in an file that will be interperatable fo ms excell. Is that possible? say for example i take this snippet of data:

 {"d":[["","","y","ZAR","1","49517","6458, 8270, 8270, 8270, 7635",null,"1.40","6458","0:13:30","","12","","C","30",null],["y","-00:00","y","ZAR","2","49593","6458, 6458, 6458, 6458, 6458",null,"2.92","6458","0:13:37","","12","","L","12","Ve4mYdrvkkQMKxBH1\/1VMtDTCDQBRspg5jB8jjY08zg="],["","","y","ZAR","3","49058","7456, 9216, 6458, 5153, 7456",null,"194.40","7456","0:00:31","","1100","","T",null,null],["","","y","ZAR","4","49597","2935, 6554",null,"1.22","2935","0:01:16","","12","","T",null,null],["","","y","ZAR","5","49590","4440, 0518, 5343, 2625, 4848",null,"0.95","4440","0:15:58","","5","","L",null,null],["","","y","ZAR","6","49591","4848, 4440, 4440, 0518, 2625",null,"1.81","4848","0:16:05","","12","","L",null,null],["","","y","ZAR","7","49595","6458",null,"5.55","6458","0:04:13","","55","","T",null,null],["","","y","ZAR","8","49596","",null,"2.90","NONE","0:04:35","","29","","T",null,null],["","","y","ZAR","9","49496","6458, 2427, 2427, 7863, 5845",null,"2.56","6458","0:06:07","","10","","B",null,null],["","","y","ZAR","10","49524","6458, 2427, 7863, 7863, 5845",null,"1.67","6458","0:06:00","","5","","B",null,null],["","","y","ZAR","11","49539","6458, 2427, 7863, 7863, 0764",null,"2.02","6458","0:04:25","","10","","B",null,null]]}

,将其读取到2D数组中,Brock Adams帮了我忙.

, Read it into an 2d array, which Brock Adams helped me with.

var myJson              = '{"d":[["","","y","ZAR","1","49517","6458, 8270, 8270, 8270, 7635",null,"1.40","6458","0:13:30","","12","","C","30",null],["y","-00:00","y","ZAR","2","49593","6458, 6458, 6458, 6458, 6458",null,"2.92","6458","0:13:37","","12","","L","12","Ve4mYdrvkkQMKxBH1\/1VMtDTCDQBRspg5jB8jjY08zg="],["","","y","ZAR","3","49058","7456, 9216, 6458, 5153, 7456",null,"194.40","7456","0:00:31","","1100","","T",null,null],["","","y","ZAR","4","49597","2935, 6554",null,"1.22","2935","0:01:16","","12","","T",null,null],["","","y","ZAR","5","49590","4440, 0518, 5343, 2625, 4848",null,"0.95","4440","0:15:58","","5","","L",null,null],["","","y","ZAR","6","49591","4848, 4440, 4440, 0518, 2625",null,"1.81","4848","0:16:05","","12","","L",null,null],["","","y","ZAR","7","49595","6458",null,"5.55","6458","0:04:13","","55","","T",null,null],["","","y","ZAR","8","49596","",null,"2.90","NONE","0:04:35","","29","","T",null,null],["","","y","ZAR","9","49496","6458, 2427, 2427, 7863, 5845",null,"2.56","6458","0:06:07","","10","","B",null,null],["","","y","ZAR","10","49524","6458, 2427, 7863, 7863, 5845",null,"1.67","6458","0:06:00","","5","","B",null,null],["","","y","ZAR","11","49539","6458, 2427, 7863, 7863, 0764",null,"2.02","6458","0:04:25","","10","","B",null,null]]}'
var jsonObj             = $.parseJSON (myJson);

//--- The JSON should return a 2-D array, named "d".
var arrayOfAuctions     = jsonObj.d;

//--- Loop over each row in the array.
$.each (
    arrayOfAuctions,
    function (rowIndex, singleAuctionData) {

        //--- Print the 7th column.
        console.log ('Row: ' + (parseInt (rowIndex) + 1) + ' Column: 7  Value: ' + singleAuctionData[6]);
    }
);

现在我想将数组的数据写到一个文件中,以后可以在excell中打开它并对其进行遍历.通过使用GM_setValue可以完成吗?进行下去最简单的方法是什么?

now i want to write this data of the array over into an file which i can later go and open in excell and go over it. By using GM_setValue, can it be done? How would the easiest way be to go on with it?

谢谢.

推荐答案

Greasemonkey无法写入文件,而使用GM_setValue或本地存储将很难进入文件.无论如何,您都不希望使用GM_setValue存储很多值,因为这些值存储在浏览器首选项中.

Greasemonkey cannot write to a file, and using GM_setValue or local storage would be a pain to get into a file. You do not want to store very many values using GM_setValue anyway, since these are stored in the browser preferences.

您提到了远程服务器.
是的,GM可以将数据发送到远程服务器(如果运行的是XAMPP,甚至可以发送到本地计算机).经过更多的工作,您还可以将数据发送到Google文档或类似文件.

You mentioned a remote server.
Yes, GM can send the data to a remote server (or even your local machine if it is running something like XAMPP). With a little more work, you could also send the data to Google docs, or similar.

尚不清楚您要发送什么数据(假设您不只是发送整个arrayOfAuctions).

It's not clear what data you want to send (assuming you don't just send the entire arrayOfAuctions).

也就是说,您已经分析了数据并确定需要这些列:

So, say, you've analyzed the data and determined that you want these columns:


Column 
Index       Meaning / Purpose
------      --------------------------------
   4        Auction display number
   5        Auction ID
   8        Current Price
   9        High bidder ID
  10        Time Remaining
  12        Up to???


然后,您可以像这样隔离感兴趣的数据:


Then you could isolate the data of interest like so:

//--- Start custom, 2-D array.
var myAuctionData       = [ [ 'DisplayNumber', 'AuctionID', 'CurrentPrice',
                            'HighbidderID', 'TimeRemaining', 'Upto'
                        ] ];

//--- Loop over each row in the array, storing desired data.
$.each (
    arrayOfAuctions,
    function (rowIndex, singleAuctionData)
    {
        myAuctionData.push ( [
            singleAuctionData[4], singleAuctionData[5],  singleAuctionData[8],
            singleAuctionData[9], singleAuctionData[10], singleAuctionData[12]
        ] );
    }
);


并将其发送到您的服务器,如下所示:


And send it to your server like so:

SerializedAuctionData  = JSON.stringify (myAuctionData);

GM_xmlhttpRequest ( {
    method:     "POST",
    url:        "http://localhost/YourDir/LogAuctionData.php",
    data:       SerializedAuctionData,
    headers:    {"Content-Type": "application/json"}
} );


服务器可以使用您喜欢的任何技术.
如果它是PHP页面,则可以像这样提取JSON数据:


The server can be using whatever technology you are comfortable with.
If it was a PHP page, it could extract the JSON data like so:

$AuctionData = json_decode($HTTP_RAW_POST_DATA);
print_r ($AuctionData);


服务器页面可以编写一个csv或xls文件,但是由于每秒将发布大量数据,因此使用mySQL数据库可能会更聪明.


The server page could write a csv or xls file, but since lots of data will be posted, once per second, it would probably be smarter to use a mySQL database.

这篇关于用油脂猴子存储或登录数据,以后可以处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆