如何通过"多因素"机械化认证?

时间:2014-08-20 05:16:57

标签: ruby web-scraping nokogiri screen-scraping mechanize

我试图通过Mechanize登录一个网站,这被证明是一个挑战。我可以通过前两个表单页面,但在提交了ID和密码之后,我可以在进入我试图抓取的主要内容之前获得第三页。

在我的情况下,我有以下Ruby源代码,让我到达了我遇到障碍的地步:

agent = Mechanize.new


start_url = 'https://sub.domain.tld/action'

# Get first page
page = agent.get(start_url)

# Fill in the first ID field and submit form
login_form = page.forms.first
id_field = login_form.field_with(:name => "ctl00$PageContent$Login1$IdTextBox")
id_field.value = "XXXXXXXXXXX"

# Get the next password page & submit form:
page = agent.submit(login_form, login_form.buttons.first)
login_form = page.forms.first
password_field = login_form.field_with(:name => "ctl00$PageContent$Login1$PasswordTextBox")
password_field.value = "XXXXXXXXXXX"

# Get the next page and... 
page = agent.submit(login_form, login_form.buttons.first)

# Try to go into the main content, just to hit a wall. :s
page = agent.click(page.link_with(:text => /Skip to main/))

根据mechanize代理输出的第三页内容是:

https://gist.github.com/5ed57292c8f6532352fd

正如您可能从中注意到的那样,似乎应该能够在第一个链接上使用agent.click来进入主要内容。不幸的是,这只是循环回到这个页面。每次加载时我都会看到它正在加载一个新页面,但每次都会得到精确相同的内容。有些东西阻止我通过这个多因素登录继续看它看起来的主要内容,但是我不能指出那可能是什么。

以下是第三次请求中的page.contenthttp://f.cl.ly/items/252y261c303R0m2P1R0j/source.html

有什么想法阻止我在这里停止内容?

0 个答案:

没有答案