Create Operator or Output with Groovy

darktemptationdarktemptation MemberPosts:4Contributor I
edited June 2019 inHelp
My Problem is quite simple:
I want to load a Webpage with Groovy in a Text-Operator (i.e. Document) and then extract certain attributes (e.g. all
  • -Texts).

    Now I can fetch the HTML from a page with

    "http://rapid-i.com".toURL().text
    But the Script Operator does not return anything to the output, even when I use the "return" from Groovy.

    Can somebody give me a hint?
  • Tagged:

    Answers

    • steffensteffen MemberPosts:347Maven
      Hm ... maybe I didnt grasp the problem, but rapidminer cannot deal with arbitrary groovy types. You have to convert the output into an IO-type rapidminer does understand.

      ... and "no", I do not know which one and how :-\.
    • haddockhaddock MemberPosts:849Maven
      Hi there,

      I think you were getting nothing back because you were being re-directed, the following ( with the '/' on the end of the URL ) produces words of infinite beauty, wisdom, etc..etc..







      //R5 Forum/groovout











      http://rapid-i.com/".toURL().text)"/>







    • darktemptationdarktemptation MemberPosts:4Contributor I
      Thanks for the hints so far.

      But@haddock:

      Even if I try your setting, the log tells me that there is nothing delivered to the Result 1 Port.

      And if you like you can also take another page where you aren't redirected.

      "http://www.aboutgroovy.com".toURL().text

      So the problem is still how to get the fetched result to the the output-port, with a data type that is known by RM.
      Maybe then the question must be, how can I create an IOObject with a String/Text Attribute in Groovy (as Steffen suggest)?
    • haddockhaddock MemberPosts:849Maven
      Ooops, I thought you weren't getting anything back. If you want to manipulate the contents you can with macros, and so to logs and example, like this...












      HTML







      http://rapid-i.com/" .toURL () .text.substring (0,10)); //defhtml="http://rapid-i.com/" .toURL () .text.substring (0,10)"/>



















      There's some Groovy stuff on the Wiki which may be helpful.

    • darktemptationdarktemptation MemberPosts:4Contributor I
      Thanks haddock

      This goes into the right direction, for what I looked. After a few modifications I found the way how to do it.













      HTML







      http://rapid-i.com/".toURL().text); //defhtml="http://rapid-i.com/" .toURL () .text.substring (0,10)"/>














      So I just used the scripting Operator to define the macro and used the macro as parameter for the "Create Document" Operator. This is a nice solution I think.

      Now there will be the next step, how to find all the "
    • " and write all in one Attribute.