【发布时间】:2015-11-28 11:28:46
【问题描述】:
我需要从页面中解析一个元素,该元素只有在我在网站上通过身份验证后才会出现。
认证页面是/lws/wp-login.php
这是我尝试过的,但没有奏效:
require 'rubygems'
require 'mechanize'
agent = Mechanize.new
agent.user_agent_alias = 'Windows Mozilla'
agent.add_auth('http://example.com/lws/wp-login.php', 'login', 'pass')
agent.get('http://example.com/assimil-pour-mieux-connaitre-le-chinois/') do |page|
puts page.parser.css("p[style='text-align: center;'] strong")[0]
end
【问题讨论】:
-
“没用”是什么意思?请阅读“How to Ask”。