gpt4 book ai didi

javascript - 使用 Jsoup 获取脚本标签内的文本

转载 作者:行者123 更新时间:2023-11-29 19:11:21 27 4
gpt4 key购买 nike

如何获取值http://api.tivi8k.net/viettel/?cid=154&token=-OWPRmOicPqIKsK97SmOlQ&e=1500542988使用 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代码

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();
}

请多多支持。感谢支持

最佳答案

此代码将占用所有 <script>元素并遍历每个元素,然后它会检查他看起来是不是你想要的行 : pattern在这里,如果它matches需要 group(1) (代表捕获组 (.*)group(0) 是整行):

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

关于javascript - 使用 Jsoup 获取脚本标签内的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45214208/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com