2

(HTMLフォームを介して認証した後)追跡/レポートアプリに1000のURLをロードし、「再送信」javascript関数をトリガーする必要があります。残念ながら、一度にすべてを処理する一括アクションはないため、自動化が必要になります。私のオプションは何ですか?

http://domain.com/0001.php
http://domain.com/0002.php
http://domain.com/0003.php
...
http://domain.com/1000.php

上記の各ページには、hrefによってトリガーされるresubmit()javascript関数があります。これらのトリガーを自動化するにはどうすればよいですか?

例:

<form action="/resubmit" method="POST">
  <input type="hidden" name="security_token" value="SUPER-LONG-HASH">
  <input type="hidden" name="url" value="http://mysite.com/0001.html">
  <input type="hidden" name="redirect" value="long-string">
  <script type="text/javascript">
    window["resubmit"] = function () {
      document["resubmit"].submit();
      return false;
    }
  </script>
  <a href="javascript:resubmit()" class="resubmit-class">resubmit</a>
</form>

私はMacを使用しています。Unix、Perl、Bash、PHP、Automator、FireFoxiMarcosがすべて利用可能です。

4

4 に答える 4

3

PhantomJS、「JavaScriptAPIを備えたヘッドレスWebKit」をチェックする必要があります。これにより、コマンドラインからWebKitブラウザインスタンスを実行し、Javascriptを実行できます。

PhantomJS上に構築されたツールであるPjscrapeを使用すると、時間を節約できる可能性があります。このツールは、複数のページをスパイダーしたり、URLの長いリストを取得したりできます(免責事項:これは私のプロジェクトです)。1,000以上のURLで試したことはありませんが、次の6行で説明したことを実行できると思います。

pjs.addSuite({
    urls: [...], // your very long list here
    scraper: function() {
        window.resubmit();
    }
});
于 2011-10-28T00:33:21.553 に答える
3

私はすでに他の答えに投票しましたが、結局私はまっすぐなAppleScriptを使うことになりました。これは、既存のセッションを使用していたため、認証の問題に対処する必要がなかったため、役に立ちました。みなさん、ありがとうございました。共有したツールに慣れることを楽しみにしています。

set thePath to (path to desktop as Unicode text) & "list_of_urls.txt"
set theFile to (open for access file thePath)
set theContent to (read theFile)
close access theFile

set theURLs to every paragraph of theContent

tell application "Safari"
    repeat with theURL in theURLs
        make new document
        set URL of front document to theURL
        delay 5
        set theScript to "document.getElementsByClassName('resubmit-class')[0].click();"
        do JavaScript theScript in current tab of first window
        do JavaScript "window.resubmit()" in front document
        delay 5
        close front document
    end repeat
end tell
于 2011-10-31T16:20:11.710 に答える
2

そのためにRuby+ Watirを使用します。サンプルコード(テストされていません):

require "watir-webdriver"
browser = Watir::Browser.new :firefox

urls = ["http://domain.com/0001.php", "http://domain.com/0002.php"] # add more URLs here
urls.each do |url|
  browser.goto url
  browser.a(:text => "resubmit").click
end
于 2011-10-28T09:50:58.513 に答える
1

これがあなたに役立つかどうかはわかりませんが、Fakeを試すことができます。フォームの送信を自動化し、ループを作成できるようになると思います。

于 2011-10-29T06:08:28.477 に答える