I'm struggling some time to extract JSON data from one html tag. To be more specific it's a script tag and using JSOUP library I can get data between script tags. But inside there is some JSON data which I can't extract. Here is the tag:
<script type="text/javascript">jwplayer.key="WbtWzGvcRNi6Tk+gtKldIbx+nn6lXZFvKiaO2g==";jwplayer("tvplayer").setup({playlist:[{image: "http://img.canlitvlive.io/yayin/trt1_480.jpg?1509735585",title:"TRT 1 Canlı Yayın - CanliTVLive.io",file : "http://yayin.canlitvlive.io/trt1/live.m3u8?tkn=8JD95lXv9dOUXwtgOTBYfw&tms=1509749985"}],...</script>
I need url from file tag which is inside jwplayer. I tried using regular expression for example I tried somethig like this:
"playlist[\":\\s\\{]+file[\":\\s\\{]+\"([^\"]+)\""
But I don't have much experience with regex and can't figure out right pattern. Can someone help with this? Thanks
I'm guessing you just need some whitespace
file\s*:\s*"(.*?)"
https://regex101.com/r/4HldaP/3
Related
we have to get out all the Text from an HTML File without the usage of Jsoup or similar. Whats the best/only way to do that? Our Example looks like this:
<ul><li>Coffee</li><li>Tea</li><li>Milk</li></ul>
<h2>An Ordered HTML List</h2>
<ol><li>Coffee</li><li>Tea</li><li>Milk</li></ol>´´´
need to get all the text out of these html tags without using any libs and if the Tag is not done correctly, print out an error message. Need help guys
I use framework struts and i want display json string from variable java
String test = "{\n \"fileName\": \"\",\n \"fileUrl\": \"\",\n \"accountId\": ,\n \"totalRow\": \n}";
Display on browser :
And view source chrome browser :
How can i remove whitespace at first and last pre tag to display pretty json data
I found the problem. Because distance of pre tag and s:property tag of struts framework :
Error :
Solve : move s:property to near pre tag
<pre><s:property value="test" /></pre>
It's display pretty json data like :
I know this isn't a proper answer but I can give you a hint that You can use Regular Expressions for solving your problem. I'll surely help you.
Im using FTL for my front end . I send some objects from model map like this
model.addAttribute("xxx","myDetails");
But when i try to access it in a inline javascript inside an ftl file like this :
$('#someDiv').html({xxx});
But it cannot be accessed.Can anyone give me solution to access . I m very new to ftl so someone help me out with this
You forgot the dollar
$('#someDiv').html(${xxx});
Since FreeMarker runs on the server, you have to generate text that's valid JavaScript:
$('#someDiv').html("${xxx?js_string}")
The ?js_string is needed if there can be characters in xxx that have to be escaped in a JavaScript string literals.
I need a way to find specific tags in my class.
Example code :
<ace:column id="test1"></ace:column>
<ace:column id="test2"></ace:column>
<ice:panelGrid id="test3" columns="4" />
Now I want to process the file with above contents ,parse it and get all the tag values with identifier "id".
I would expect to get
test1
test2
test3
Thanks.
Use parsers. There are a lot of and for the tutorial on how to parse see this URL.
If you need to process the tags themselves, you would need to rely on some parser such as JSoup.
That being said, if all you want are the values following the id string, you could rely on regular expressions, somthing such as: id="([^"]*?)".
I am using this pattern to remove all HTML tags (Java code):
String html="text <a href=#>link</a> <b>b</b> pic<img src=#>";
html=html.replaceAll("\\<.*?\\>", "");
System.out.println(html);
Now, I want to keep tag <a ...> (with </a>) and tag <img ...>
I want the result to be:
text <a href=#>link</a> b pic<img src=#>
How to do this?
I don't need HTML parser to do this,
because I need this regex pattern to filter a lot of html fragment,
so,I want the solution with regex
You could do this using a negative lookahead:
"<(?!(?:a|/a|img)\\b).*?>"
Rubular
However this has a number of problems and I would recommend instead that you use an HTML parser if you want a robust solution.
For more information see this question:
What HTML parsing libraries do you recommend in Java
Check this out http://sourceforge.net/projects/regexcreator/ . This is very handy gui regex editor.
Hey! Here is your answer:
You can’t parse [X]HTML with regex.
Use a proper HTML parser, for example htmlparser, Jericho or the validator.nu HTML parser. Then use the parser’s API, SAX or DOM to pull out the stuff you’re interested in.
If you insist on using regular expressions, you’re almost certain to make some small mistake that will lead to breakage, and possibly to cross-site scripting attacks, depending on what you’re doing with the markup.
See also this answer.
I recommend you use strip_tags (a PHP function)
string strip_tags ( string $str [, string $allowable_tags ] )
<?php
$text = '<p>Test paragraph.</p><!-- Comment --> Other text';
echo strip_tags($text);
echo "\n";
// Allow <p> and <a>
echo strip_tags($text, '<p><a>');
?>
OUTPUT
Test paragraph. Other text
<p>Test paragraph.</p> Other text