如果链接包含特定关键字,则如何自动单击链接



有一个网页有一堆链接。
所有这些链接都将与javascript的onclick函数一起使用。
每个链接都有参数,这些参数将用于决定着陆页。

在这种情况下,如果链接始终具有相同的关键字,我如何编写Applescript以跳转到特定页面。

我正在使用脚本编辑器在MaxOS Lion上使用Safari自动执行此操作。

我认为Chrome对Javascript命令的响应更好。

set myKeyword to "questions"
tell application "Google Chrome"
    tell window 1 to tell active tab
        set URL to "http://stackoverflow.com/"
        delay 3
        set num_links to (execute javascript "document.links.length") - 1
        repeat with i from 0 to num_links
            set myLink to execute javascript "document.links[" & i & "].href"
            if myLink contains myKeyword then
                execute javascript "document.links[" & i & "].click()"
            end if
        end repeat
    end tell
end tell