Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8915829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:04:49+00:00 2026-06-15T05:04:49+00:00

I am having trouble getting the following code to compile in groovy. String execute(Document

  • 0

I am having trouble getting the following code to compile in 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

}

This is what should be executed when I call my function like this:

//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)

What I get is this exception:

| 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

I googled this exception for a while now, but cannot come up with how to resolve this issue. Perhaps someone has experienced a similar situation already and can help me out with this.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:04:50+00:00Added an answer on June 15, 2026 at 5:04 am

    The problem is this line:

    Rule r = new Rule("select(div#unten div h2).get(1)")
    

    When you isolate the rule, you get this program:

    select(div#unten div h2).get(1)
    

    I think you want to pass a string argument to select, so this would be the correct program:

    select("div#unten div h2").get(1)
    

    This means the Rule r line should be written as follows:

    Rule r = new Rule("select(\"div#unten div h2\").get(1)")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having trouble with the following segment of code. I'm getting a parameter count mismatch.
I'm having compile time trouble with the following code: template <typename T, template <class
I'm having trouble with the following collections initialization: private Dictionary<string, string> mydictionary = new
Having trouble getting the following code to work. Calling swapLevel() directly works fine, but
I am having trouble with the following code: function initialize() { //myLatLng = new
Having trouble getting the following code to work: $('#changeMode').button().click(function(){ $('#playfield').toggle(function() { $(this).switchClass(gridView,plainView); }, function()
I am having trouble getting the following code to work in FireFox (3.6.4), however,
I'm having trouble getting the following code to work correctly. Using an online IEEE-754
I am having trouble getting the following code to work: function doGet () {
I am having trouble getting the following piece of code to work out. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.