1

我正在尝试使用 jruby 和 htmlunit 解析一个简单的 html 页面http://www.brainjar.com/java/host/test.html但我遇到了错误未定义的方法'asText'。

我的代码:

require 'java';

require 'commons-codec-1.7.jar';
require 'commons-collections-3.2.1.jar';
require 'commons-io-2.4.jar';
require 'commons-lang3-3.1.jar';
require 'commons-logging-1.1.1.jar';
require 'cssparser-0.9.8.jar'
require 'htmlunit-2.11.jar'
require 'htmlunit-core-js-2.11.jar'
require 'httpclient-4.2.2.jar'
require 'httpcore-4.2.2.jar'
require 'httpmime-4.2.2.jar'
require 'jetty-http-8.1.7.v20120910.jar'
require 'jetty-io-8.1.7.v20120910.jar'
require 'jetty-util-8.1.7.v20120910.jar'
require 'jetty-websocket-8.1.7.v20120910.jar'
require 'nekohtml-1.9.17.jar'
require 'sac-1.3.jar'
require 'serializer-2.7.1.jar'
require 'xalan-2.7.1.jar'
require 'xercesImpl-2.10.0.jar'
require 'xml-apis-1.4.01.jar'

java_import 'com.gargoylesoftware.htmlunit.WebClient';


def get_desc
  wc = WebClient.new;

  page = wc.getPage("http://www.brainjar.com/java/host/test.html");

  a =  page.getByXPath('/html/body/p')
  ss = a
  puts ss.asText
end

get_desc
4

0 回答 0