我遇到了这个简单脚本的错误。它是使用Safari验证具有多个验证站点的RSS源的验证器。只要Feed在=符号后面不包含特殊字符或任何内容,一切正常。
脚本应验证复制到剪贴板的Feed。
例如,此Feed可以正常运行:http://thefirst.libsyn.com/rss
此Feed在?id:https://www.npr.org/rss/podcast.php?id=510298
之后被截断这只发生在Podbase验证站点上。
如果我可以让脚本单击Validate和Go按钮,这将是惊人的,但这是非常基本的...只是坚持为什么Feed被截断。
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 :(得分:0)
问题在于https://podba.se/validate
只使看起来就像单个GET
请求就足够了,而单击Go按钮会以交互方式执行许多单独的GET
个请求在当前页面上将结果拼凑在一起的幕后(然后修改URL以包括提交的源URL)
换句话说:即使解决(奇数)截断问题也是不够的。
因此,您最好的选择是模拟供稿网址的交互式提交,这需要在输入框中填写供稿网址并按下提交按钮。
必须为http://castfeedvalidator.com
网站模拟交互式提交,但是按下提交按钮就足够了。
(正如您所报告的那样,即使检查提交按钮发送的请求显示您的网址的变体 - 只有准备提交的供稿网址 - 可用于立即提交,这样做也不会不正确渲染结果(缺少样式))。
以下代码实现了这两个建议(模拟交互方法改编自我的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