0
   <script type="text/javascript" src="http://xyz.js"></script>
<script type="text/javascript" src="http://abc.js"></script>

I want extract these Java script values from payload ( my payload is very big .Here, I am showing the required content which need to be fetch from payload)

And i want to fetch all the js value from payload (here count is two but may be more in other cases) and retrieve these values one by one for other functionality.

I don't know how to fetch particular content from payload and if count is more than 1 than how to process all the counts one by one for other functionality.

Please Advice

Isranis
  • 103
  • 1
  • 13
  • Can you post your code so that we can understand more on what you need When the payload is very big I Suggest to use groovy instead of JavaScript so explaining your need we may arrive a solution which may not need JS at all. – Naveen Raj Aug 23 '15 at 16:35
  • Hey Naveen, js data is inside there i am not using js it is inside my payload. view-source:http://www.xalkori.com/ - goto this link this is my whole payload and i want to fetch the js scipt url as is mentined intial..please advice.. – Isranis Aug 23 '15 at 18:09
  • @AnirbanSenChowdhary please advice.. – Isranis Aug 23 '15 at 18:23
  • Do you intend to extract only the attributes of script tag or also the content? If the former, a simple regex could probably help you.. But I would suggest to parse the HTML first to DOM (eg. HTML Cleaner), then use XPath to get the elements. (see my helper class for converting to DOM, https://github.com/avanaur/stock-transactions-uploader/blob/master/src/main/java/com/avanaur/tradingintelligence/helper/HtmlHelper.java) – Avanaur Aug 24 '15 at 05:46
  • Hey Tyrone, From this link :-view-source:xalkori.com , i have extract below data And process all of them these http one by one , how can i implement this thing in mule.. – Isranis Aug 24 '15 at 06:16

3 Answers3

0

As Tyrone has suggested, you can convert the HTML into a DOM object (perhaps from a Mule component) and that way you are able to retrieve all the URLs for JS files that you wish to download. Once you have those URLs, you can use a similar approach to that discussed here.

Community
  • 1
  • 1
Gabriel Dimech
  • 699
  • 5
  • 10
  • Please check my updated comment http://stackoverflow.com/questions/32212522/extract-data-from-payload-in-mule – Isranis Aug 25 '15 at 19:34
0

If you want to extract the URLs of all script elements (value of src attribute), use this regex to extract them, \<script[^>]*src="([^\"]*)"[^>]*\>

<expression-component doc:name="Expression"><![CDATA[import java.util.regex.*;
import java.util.*;

Matcher myMatcher = Pattern.compile("\\<script[^>]*src=\"([^\\\"]*)\"[^>]*\\>").matcher(payload);

List urls = new ArrayList();
while (myMatcher.find()) {
    urls.add(myMatcher.group(1));
}

payload = urls;]]></expression-component>
Avanaur
  • 445
  • 3
  • 10
  • Please check my updated comment http://stackoverflow.com/questions/32212522/extract-data-from-payload-in-mule – Isranis Aug 25 '15 at 19:33
0

You can Use a splitter, split the content of your first site (where all the JS are listed) using "\n" expression and then use each message to check whether "JS" are there or not and then whichever message is having those JS you can capture them in a list (using groovy or java component)

Abhi
  • 16
  • 1