2011-04-17 96 views
0

腳本:油猴XPath和螢火蟲發出

從螢火的XPath按鈕如下:

.//*[@id='ctl00_mainContentPlaceholder_Button3'] 

和腳本的段子:

<br> 
    <input name="ctl00$mainContentPlaceholder$Button3" 
      value="Back To Auctions" 
      onclick="closePopup(); return false;" 
      id="ctl00_mainContentPlaceholder_Button3" 
      class="simplemodal-close" 
      style="width:160px;" 
      type="submit"> 
<br> 

我的GM腳本如下如下:

// @include * 
// @version  0.1 
// @description Automatically click // ==/UserScript== 

click_popupBtn1 = function() { 

    var joinBtn=document.evaluate(
        '//*[@id, "ctl00_mainContentPlaceholder_Button3"]', 
        document, 
        null, 
        XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, 
        null).singleNodeValue.click(); 
alert(joinBtn); 
    if(!joinBtn) return false; 
    joinBtn.click(); 
    return true; 
} 

click_popupBtn1();

我發現了這個拍賣網站,我想用通用汽車實現自動化。有兩個屏幕截圖。 www.mediafire.com/?lwy7agybtfn2x。第一個屏幕截圖是網站的基本概述,帶有出價按鈕。第二個概述,獎金彈出。

我需要做的是:首先需要一些幫助來擺脫彈出窗口。如果它在那裏我不能出價。我爲登錄頁面使用了一個類似的腳本,並設法讓GM自動登錄,因爲服務器需要您每三個小時左右登錄一次。參見上面提到的腳本和xpath。我試過了,但是我的gm腳本文件沒有點擊它。

然後項目:我想自己做一些,但我需要一些指針。上附加的txt文件,auction1.txt,我已經複製了一些Firebug的控制檯文件,這看起來像:

GET http://www.xxx.xxx/REST_Service/REST_Auction.svc/GetAuctionData?_=1303059143094 
200 OK 
29.62s firebu...rver.js (line 169) 
<System> 
ParamsHeadersResponse {"d":[["","","y","ZAR","1","33713","8887, 8887, 8887, 8887, 8887",null,"1.26","8887","0:13:30","","12","","C","29",null],["","","y","ZAR","2","34029","",null,"0.76","NONE","0:10:37","","5","","L",null,null],["","","y","ZAR","3","30332","3616, 9390, 9841, 8664, 4901",null,"379.80","3616","0:01:09","","1100","","T",null,null],["","","y","ZAR","4","33987","3616, 9168, 0605, 9168, 8771",null,"1.26","3616","0:00:51","","12","","T",null,null],["","","y","ZAR","5","34030","",null,"0.76","NONE","0:12:28","","5","","L",null,null],["y","-00:00","y","ZAR","6","34028","1137, 1137, 1137, 1137",null,"2.64","1137","0:20:05","","12","","L","12","vkSaGLYmZD+vgphl90foiM+3QXDf0c7SRfpMnt9PSDw="],["","","y","ZAR","7","33938","3616, 3616",null,"5.60","3616","0:01:50","","55","","T",null,null],["","","y","ZAR","8","33729","3616, 6197, 3616, 6197, 9134",null,"3.34","3616","0:01:26","","29","","T",null,null],["","","y","ZAR","9","33867","1551, 7243",null,"1.73","1551","0:02:40","","10","","B",null,null],["","","y","ZAR","10","33293","1551, 7243, 7243, 7243, 7243",null,"3.43","1551","0:06:10","","10","","B",null,null],["","","y","ZAR","11","33174","7243, 4901, 3614, 0481, 0481",null,"3.71","7243","0:06:10","","10","","B",null,null]]} 
GET http://www.xxx.xxx/REST_Service/REST_Auction.svc/GetAuctionData?_=1303059144766 

從那裏我可以看到我需要的所有信息,並更新每一秒,所以爲了讓我告訴GM腳本在哪個按鈕上出價,我需要將這些信息放入要處理的腳本中。有沒有人有任何想法?

我在爲12個小型拍賣的每一個寫一個小腳本,每個處理自己的部分,收集自己的信息。我認爲這些來自Firebug的反應可能是有用的,也是更直接的獲取信息的方式,即從窗口中逐一減去它們,然後再進行更新。

+0

看起來你有'ctl00 $ mainContentPlaceholder $ Button3'而不是'ctl00_mainContentPlaceholder_Button3' ... – 2011-04-17 20:57:13

+0

@ alenjandro:頁面中的腳本是:「

「 – Ludwig 2011-04-18 03:01:53

+0

但我的GM腳本我爲甲肝:」 VAR joinBtn = document.evaluate( '// * [@ id中, 「ctl00_mainContentPlaceholder_Button3」]', 文件, 空, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, 空).singleNodeValue.click();」它是ctl00_mainContentPlaceholder_Button3,所以我不知道如果我是正確的... – Ludwig 2011-04-18 03:05:09

回答

1

沒有左看右看的代碼或通過後整體更徹底地閱讀,這條線跳出我: '//*[@id, "ctl00_mainContentPlaceholder_Button3"]'

我不是100%地肯定了我的頭頂部,但我相信這也許應該是: '//*[@id="ctl00_mainContentPlaceholder_Button3"]'

我強烈建議您使用Firefinder for Firebug插件,以幫助創建的XPath路徑:]

其次,看看在Mozilla Developers Network page產生點擊事件s(iirc,joinBtn.click();在Greasemonkey腳本中不起作用)。

+0

+1,但他確實聲明他使用FireBug獲取XPath。 – 2011-07-06 00:09:54

+0

@Brock Adams:是的,他提到使用Firebug,但_Firebug!== Firefinder_。我假設他使用Firebug的HTML選項卡來獲取XPath(也許右鍵單擊節點>複製XPath?),但這與_separate addon_Firefinder的功能不同。 Firefinder是一個單獨的插件,它擴展了Firebug以在Firebug面板(Console | HTML | CSS | Script | DOM | Net [| Firefinder])上的額外選項卡中提供額外的功能。 – kwah 2011-07-06 00:21:06

+0

好的。我剛剛看到該擴展的描述:'「查找匹配所選CSS選擇器或XPath表達式的HTML元素」,並假定OP已覆蓋該部分。但是,我現在看到擴展也可能有助於測試XPath查詢。 – 2011-07-06 00:43:10