我想登录社区服务器的论坛部分(例如 http://forums.timesnapper.com/login.aspx?ReturnUrl=/forums/default.aspx )然后下载特定页面并执行正则表达式(以查看是否有任何帖子在等待适度)。如果有的话,我想发一封电子邮件。

我想从Linux服务器上执行此操作。

目前我知道如何下载页面(使用例如wget)但登录时遇到问题。有什么明智的想法是如何工作的?

有帮助吗?

解决方案

查看登录页面的来源,它似乎是一个asp.net应用程序,所以你可能需要做几件事来实现这个目标 -

管理表单隐藏的__viewstate字段,并在您提交登录详细信息时将其发回。

一旦你过去,我猜你可以使用绝对URL引用有问题的特定页面,但是你需要处理ASP.NET Forms身份验证cookie并将其作为GET请求的一部分发送。 / p>

其他提示

你可能有更好的运气与Selenium或看到这个问题以获得更多建议:

大学课程注册脚本

就个人而言,我是用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的力量。

你可以用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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top