次のコードを groovy でコンパイルするのに問題があります。
String execute(Document doc){
CompilerConfiguration configuration = new CompilerConfiguration()
configuration.setSourceEncoding("UTF-8")
binding = new Binding();
binding.setVariable("doc", doc)
shell = new GroovyShell(binding, configuration)
String clipping = shell.evaluate("doc."+jsoupExpression+".text()")
return clipping
}
これは、次のように関数を呼び出すときに実行する必要があるものです。
//Use a document from test/resources as input
Document doc = Jsoup.parse(new File("test/resources/online.html"), "UTF-8")
//This is what gets passed as jsoupExpression
Rule r = new Rule("select(div#unten div h2).get(1)")
String result = r.execute(doc)
私が得るのはこの例外です:
| Failure: testExecute(com.threefact.scrapetastic.RuleTests)
| org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 1: unexpected char: '#' @ line 1, column 15.
doc.select(div#unten div h2).get(1).text()
^
1 error
この例外をしばらくグーグルで検索しましたが、この問題を解決する方法がわかりません。おそらく、誰かがすでに同様の状況を経験しており、これで私を助けることができます.
ありがとう。