2008-11-19 109 views
0

我想登錄到社區服務器的論壇部分(例如http://forums.timesnapper.com/login.aspx?ReturnUrl=/forums/default.aspx),然後下載特定頁面並執行正則表達式(查看是否有任何帖子在等待審覈)。如果有,我想發一封電子郵件。以編程方式登錄論壇,然後屏幕截圖

我想從Linux服務器上執行此操作。

當前我知道如何下載一個頁面(例如使用wget),但登錄時出現問題。任何明智的想法如何工作?

回答

1

看着它似乎是一個asp.net應用程序,所以你需要在登錄頁面的源代碼可能會做一些事情來實現這一點 -

管理表單隱藏__viewstate字段,並提交後,當您提交登錄的詳細信息。

一旦你過去了,我猜你可以使用絕對URL引用問題的特定頁面,但是你需要處理ASP.NET Forms身份驗證cookie並將其作爲GET請求的一部分發送。

+0

呀,這更像是我腦子裏想的...但它看起來像一個大麻煩! – AtliB 2008-11-20 00:22:49

1

就個人而言,我會寫在Perl,使用WWW::Mechanize,並且這樣做:


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的強大功能。

0

你可以用wget完成所有工作。您需要使用POST提交表單並需要存儲Cookie。從wget的手冊頁相關的東西:

--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 
相關問題