javascript - Detect text in script and Obtain text within script tag using Jsoup -
this question exact duplicate of:
- i can't value script jsoup 1 answer
i want code value stream fail. url detect http://m.xemtvhd.com/vtv1.php
how value stream : http://123.30.215.65/hls/4545780bfa790819/5/3/d836ad614748cdab11c9df291254cf836f21144da20bf08142455a8735b328ca/dnr2mq==_m.m3u8 using jsoup ?
<html> <head> <style>html,body{margin:0;padding:0;background:#000;;}</style> <meta charset="utf-8"> <script src="https://code.jquery.com/jquery-2.1.4.js"></script> <script type="text/javascript" src="https://cdn.jsdelivr.net/clappr/latest/clappr.min.js"></script> <meta name="referrer" content="no-referrer"> </head> <body> <div style="width: 100%;"> </div> <div id="player"></div> <script> player = new clappr.player({source: "http://123.30.215.65/hls/4545780bfa790819/5/3/d836ad614748cdab11c9df291254cf836f21144da20bf08142455a8735b328ca/dnr2mq==_m.m3u8", parentid: '#player', width: '100%', height: "100%", hidemediacontrol: true, autoplay: true }); </script> </body> </html>
code java me :
elements script = doc.select("script"); pattern p = pattern.compile("player = new clappr.player(\\(\"source:{\", \"(.*)\", false\\)"); // ^^ capturing group string url = ""; (element element : script) { matcher m = p.matcher(element.data()); if (m.find()){ url = m.group(1); } } system.out.println(url);
there mistakes in regex, ex put {
after source
in fact it's before , need double escape because {i,j}
quantifiers, , ,
not @ place, don't know why did that, it's not same order sentence
so fix use : pattern.compile("player = new clappr\\.player\\(\\{source: \"(http:.*)\",.*");
when use regex, try online regex101 , write regex word word, , @ end can try replace word/group \d, \w,... reduce
Comments
Post a Comment