I want to parse a Custom Search Element JavaScript
function.
Here's a template of this function https://developers.google.com/custom-search/docs/element#overview.
<!-- Put the following javascript before the closing tag. -->
<script>
(function() {
var cx = '123:456'; // Insert your own Custom Search engine ID here
var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true;
gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s);
})();
</script>
<!-- Place this tag where you want both of the search box and the search results to render -->
<gcse:search></gcse:search>
I want to parse this function from this site http://findmusicbylyrics.com/search.php?cx=partner-pub-1936238606905173%3A1893984547&cof=FORID%3A10&ie=UTF-8&q=Love&sa=Search+Lyrics which it's JavaScript
is:
<script>
(function() {
var cx = 'partner-pub-1936238606905173:8242090140';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = 'http://www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
</script>
<gcse:search></gcse:search>
Now i have no idea of where to start with it. I've done some HTML
parsing using java Jsoup
but this is the first time i bump into this CSE
<script>
tag to parse.
Any suggestions will be very appreciated.
You'll fetch the page and then find the script element. Once done, you'll call the
html()
method on this element.HELPER FUNCTION
SAMPLE CODE
OUTPUT