1

How to get value http://api.tivi8k.net/viettel/?cid=154&token=-OWPRmOicPqIKsK97SmOlQ&e=1500542988 using Jsoup?

enter image description here

html:

xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "http://api.tivi8k.net/viettel/?cid=154&token=-OWPRmOicPqIKsK97SmOlQ&e=1500542988", false);
xmlhttp.send();
link = xmlhttp.responseText;

player = new Clappr.Player({
  source: link,
  parentId: '#player',
  width: '100%',
  height: "100%",
  hideMediaControl: true,
  mediacontrol: {
    seekbar: "#ffaa56",
    buttons: "#ff7f00"
  },
  autoPlay: true
});
html,
body {
  margin: 0;
  padding: 0;
  background: #000;
  ;
}
<div style="width: 100%;">
  <div id="player"></div>
</div>

<img src="sv2.png" style="position:absolute;top:5px;right:10px" />

Java code

try {
    String userAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36";
    Document doc = Jsoup.connect("http://m.xemtvhd.com/vtv1.php").userAgent(userAgent).get();

    String url = doc.select("#xmlhttp.open").first().attr("data-source");

    System.out.println(url);

} catch (IOException e) {
    e.printStackTrace();
}

Please support . Thank for support

H. Pauwelyn
  • 13,575
  • 26
  • 81
  • 144
Xuân Mai
  • 45
  • 1
  • 10
  • The website you have in your example do not contains all the element which are in you screen, normal ? – azro Jul 20 '17 at 12:25
  • @azro yeah. please see html in url http://m.tivi8k.net/htv1.php – Xuân Mai Jul 20 '17 at 12:43
  • @azro please support https://stackoverflow.com/questions/45313165/detect-text-in-script-and-obtain-text-within-script-tag-using-jsoup – Xuân Mai Jul 25 '17 at 22:55

1 Answers1

2

This code will take all <script> elements and iterate over each, then it will check is the one he look is the one with the line you want : the pattern is here for, if it matches it will take the group(1) (represent the capturing group (.*), the group(0) is the whole line) :

Elements script = doc.select("script");
Pattern p = Pattern.compile("xmlhttp.open\\(\"GET\", \"(.*)\", false\\)");
                                                    //  ^^ is the capturing group
String url = "";

for (Element element : script) {
    Matcher m = p.matcher(element.data());
    if (m.find()){
        url = m.group(1);
    }
}
System.out.println(url); //-> http://...542988
azro
  • 53,056
  • 7
  • 34
  • 70
  • Another one going to hell trying to parse xml to regex, it will make you insane and others you fool into that lost quest ;) check this: https://stackoverflow.com/a/1732454/24099 Seriously now do use a parser not regex.... – Apóstolo Dec 26 '22 at 22:27