2016-12-27 30 views
1

我遇到了這個簡單腳本的錯誤。這是一個使用Safari驗證RSS源與多個驗證站點的驗證器。只要Feed在=符號後面不包含特殊字符或任何內容,一切正常。Applescript:截斷的供稿網址

腳本應驗證複製到剪貼板的供稿。

例如,該飼料正常工作:http://thefirst.libsyn.com/rss

這種飼料被編號後截斷:https://www.npr.org/rss/podcast.php?id=510298

這僅發生在Podbase驗證網站。

如果我可以讓腳本點擊Validate和Go按鈕,那會很棒,但這是非常基本的......只是停留在爲什麼飼料被截斷。


set feed_url to the clipboard as string 

set the podbaseurl to "http://podba.se/validate/?url=" & feed_url 
set the feedvalidatorurl to "http://feedvalidator.org/check.cgi?url=" & feed_url 
set the castfeedurl to "http://castfeedvalidator.com/?url=" & feed_url 

tell application "Safari" 
    make new document 
    open location podbaseurl 
    open location feedvalidatorurl 
    open location castfeedurl 
end tell 

回答

0

的問題是,https://podba.se/validate只是使它看起來像一個單一的GET要求是不夠的,而點擊Go按鈕交互進行,其結果就被拼接在一起,幕後許多個人GET請求當前頁面(然後修改URL以包含提交的源URL)。換句話說,即使解決(奇數)截斷問題也是不夠的。

因此,您最好的選擇是模擬交互式提交Feed URL,該提要需要填寫包含Feed URL的輸入框並按提交按鈕。

但是,必須爲http://castfeedvalidator.com網站模擬交互式提交,但在提交按鈕已足夠的情況下也是如此。
(正如您所報告的,儘管檢查提交按鈕發送的請求表明,您的URL的變體(只有準備提交的提要URL)可用於立即提交,但這樣做不會呈現結果正確(缺少樣式))。

下面的代碼實現兩項建議(仿真的交互的方式,從我的this answer改編):

# Sample value 
set the clipboard to "https://www.npr.org/rss/podcast.php?id=510298" 

set feed_url to the clipboard as string 

# Base URL only; the feed URL will be submitted by simulated interaction below. 
set the podbaseurl to "http://podba.se/validate/" 
set the feedvalidatorurl to "http://feedvalidator.org/check.cgi?url=" & feed_url 
set the castfeedurl to "http://castfeedvalidator.com/?url=" & feed_url 


tell application "Safari" 

    activate 
    set newDoc to make new document 
    set newWin to front window 

    # Simulate interactive submission of feed_url at podbaseurl. 
    set URL of newDoc to podbaseurl 
    my submitUrl(newDoc, podbaseurl, feed_url) 

    # The feedvalidateorurl can be opened normally. 
    open location feedvalidatorurl 

    # Simulate interactive submission of feed_url at castfeedurl. 
    set newTab to make new tab in newWin 
    set URL of newTab to castfeedurl 
    my submitUrl(newTab, castfeedurl, feed_url) 

end tell 


on submitUrl(doc, target_url, feed_url) 

    # Synthesize the JavaScript command. 
    set jsCode to " 
     (function() { // Use a closure to avoid polluting the global namespace. 
      function doIt(t) { // Helper function 
       if (doIt.done) return; // Already successfully called? Ignore. 
       try { 
        // Perform the desired action - may fail if invoked too early. 
       if (/^http:\\/\\/podba.se/.test('" & target_url & "')) {     
         document.querySelector('#url-input').value = '" & feed_url & "'; 
         document.querySelector('#url-input').dispatchEvent(new Event('input')); 
         setTimeout(function() { document.querySelector('#go-button').click(); }, 0); 
       } else { // http://feedvalidator.org 
        document.querySelector('.btn-subscribe').click() 
        } 

      } catch(e) { 
       return; // Return without setting the success 'flag'. 
       } 
       doIt.done=true; // Set success 'flag' as a property on this function object. 
      }; 
      // Attach a listener to the window's load event for invoking the helper function then. 
      window.addEventListener('load', doIt); 
      // If the document signals readiness -- which may still be too early, we can't know -- 
      // also try to invoke the helper function *directly*. 
      if (document.readyState === 'complete') { doIt(); } 
     })(); 
    " 
    # Execute the JavaScript command in the target page. 
    tell application "Safari" 
     tell doc to do JavaScript jsCode 
    end tell 

end submitUrl 
+0

哇,太感謝你了。這一切都很好。唯一令人覺得奇怪的是,轉換驗證會在驗證並刪除所有樣式之後打破結果頁面,而不是使用ajax,並且只需粘貼Feed並按下驗證Feed按鈕即可。 – Ronc

+0

這是一項了不起的工作,而且時間很短。我不知道我是否會想到這一切。 如果我可以讓Cast Feed上的驗證頁面正確顯示,我會被設置。也許這是JavaScript? – Ronc

+0

@Ronc:明白了。我沒有注意風格。我想Ajax調用的結果與現有頁面結合在一起,因此交互式提交也必須在那裏進行模擬 - 請參閱我的更新。 – mklement0