質問

コミュニティサーバーのフォーラム部分にログインしたい(例 http://forums.timesnapper.com/login.aspx?ReturnUrl=/forums/default.aspx )、特定のページをダウンロードして正規表現を実行します(待機中の投稿があるかどうかを確認します)節度のため)。あれば、メールを送りたいです。

Linuxサーバーからこれを行いたい。

現在、(wgetなどを使用して)ページをダウンロードする方法を知っていますが、ログインに問題があります。

役に立ちましたか?

解決

ログインページのソースを見ると、asp.netアプリのように見えるので、おそらくこれを実現するにはいくつかのことを行う必要があります。

フォームの非表示__viewstateフィールドを管理し、ログインの詳細を送信するときにそれをポストバックします。

絶対URLを使用するだけで問題の特定のページを参照できると思いますが、ASP.NETフォーム認証Cookieを処理し、GETリクエストの一部として送信する必要があると思います。

/ p>

他のヒント

Seleniumの方が幸運かもしれません。または、より多くの提案についてはこの質問を参照してください:

大学のクラス登録用のスクリプト

個人的には、 WWW :: Mechanize を使用してPerlで記述します、次のようなことをします:


my $login_url = 'login url here';
my $username = 'username';
my $password = 'password';
my $mech = new WWW::Mechanize;
$mech->get($login_url)
    or die "Failed to fetch login page";
$mech->set_visible($username, $password)
    or die "Failed to find fields to complete";
$mech->submit
    or die "Failed to submit form";

if ($mech->content() =~ /posts awaiting moderation/i) {
    # Do something here
}

コミュニティサーバーへのログインの詳細(それが何であれ)をテストしていないため、上記が機能するかどうかはわかりませんが、十分に簡単に作業できるものを提供する必要があります。 WWW :: Mechanizeの威力を示しています。

すべてをwgetで実行できます。 POSTを使用してフォームを送信し、Cookieを保存する必要があります。 wgetのmanページからの関連事項:

--post-data=string
--post-file=file

Use POST as the method for all HTTP requests and send the specified data in the request body.
"--post-data" sends string as data, whereas "--post-file" sends the contents of file.  Other than
that, they work in exactly the same way.

This example shows how to log to a server using POST and then proceed to download the desired pages,
presumably only accessible to authorized users:

       # Log in to the server.  This can be done only once.
       wget --save-cookies cookies.txt \
            --post-data 'user=foo&password=bar' \
            http://server.com/auth.php

       # Now grab the page or pages we care about.
       wget --load-cookies cookies.txt \
            -p http://server.com/interesting/article.php
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top