문제

커뮤니티 서버의 포럼 부분에 로그인하고 싶습니다 (예 : http://forums.timesnapper.com/login.aspx?returnurl=/forums/default.aspx) 그런 다음 특정 페이지를 다운로드하고 Regex를 수행하십시오 (중재를 기다리는 게시물이 있는지 확인하십시오). 있다면 이메일을 보내고 싶습니다.

Linux 서버에서 이것을하고 싶습니다.

현재 페이지를 다운로드하는 방법을 알고 있지만 (예 : WGET 사용) 로그인하는 데 문제가 있습니다. 어떻게 작동하는지 밝은 아이디어가 있습니까?

도움이 되었습니까?

해결책

로그인 페이지의 소스를 보면 ASP.NET 앱인 것처럼 보이므로이를 달성하기 위해 몇 가지 작업을 수행해야 할 것입니다.

HIDDEN __VIEWSTATE 필드 양식을 관리하고 로그인 세부 정보를 제출할 때 다시 게시하십시오.

과거가 지나면 절대 URL을 사용하는 것만으로 해당 특정 페이지를 참조 할 수 있지만 ASP.NET 양식 인증 쿠키를 처리하고 GET 요청의 일부로 보내야합니다.

다른 팁

더 많은 제안을 위해 셀레늄에 더 나은 행운을 누리 거나이 질문을 볼 수 있습니다.

대학 수업 등록 대본

개인적으로, 나는 그것을 Perl에 사용하여 썼습니다 www :: 기계화, 다음과 같은 일을하십시오.


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 :: 기계화.

당신은 wget으로 모든 것을 할 수 있습니다. Post를 사용하여 양식을 제출해야하며 쿠키를 저장해야합니다. 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