gpt4 book ai didi

javascript - 在 JavaScript 中为 jsoup 设置 url

转载 作者:行者123 更新时间:2023-11-28 07:57:04 25 4
gpt4 key购买 nike

我想在 JavaScript 脚本中设置 url 以使用 jsoup,但我不知道如何操作。

这是我尝试过的:

<script language="javascript">
var flObject = swfobject.getFlashPlayerVersion();
var isHtml5 = (location.search.indexOf('isHtml5') != -1) ? true : false;
var isDisHtml5 = false;
switch (true) {
case navigator.userAgent.indexOf('Firefox') > -1:
isDisHtml5 = true;
break;
case navigator.userAgent.indexOf('MSIE') > -1:
isDisHtml5 = true;
break;
}
if ((!isDisHtml5 && flObject.major == 0) || isHtml5) {
zm('#oplayer').remove();
zm('#_htmlPlayer').removeClass('none');
var HTML5_SKIN = 'skins/jplayer_01';
document.write('<link href="http://static.mp3.zdn.vn/' + HTML5_SKIN + '/css/skin.css" rel="stylesheet" type="text/css" />');
zmCore.addScript('http://static.mp3.zdn.vn/' + HTML5_SKIN + '/js/jquery.min.js', function () {
zmCore.addScript('http://static.mp3.zdn.vn/' + HTML5_SKIN + '/js/jquery.jplayer.min.js', function () {
$("#jquery_jplayer_1").jPlayer({
ready: function () {
$(this).jPlayer("setMedia", {
mp3: "[http://mp3.zing.vn/html5/song/LHcnypFzWANATyDGkH][1]"
});
$(this).jPlayer("play");
},
solution: "html",
supplied: "mp3"
});
});
});
}
</script>

在此函数中:

$(this).jPlayer("setMedia", {
mp3: "[http://mp3.zing.vn/html5/song/LHcnypFzWANATyDGkH][1]"
});
$(this).jPlayer("play");

我正在尝试获取 mp3:http://mp3.zing.vn/html5/song/LHcnypFzWANATyDGkH

最佳答案

import java.util.ListIterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.text.html.HTML.Tag;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class Main {

public static void main(String[] args) {
try {
Pattern pattern = Pattern.compile(".*mp3\\s*:\\s*[\"|']\\[([^\\]]+)\\].*");

String html = "<script language=\"javascript\"> var flObject = swfobject.getFlashPlayerVersion(); var isHtml5 = (location.search.indexOf('isHtml5') != -1) ? true : false; var isDisHtml5 = false; switch (true) { case navigator.userAgent.indexOf('Firefox') > -1: isDisHtml5 = true; break; case navigator.userAgent.indexOf('MSIE') > -1: isDisHtml5 = true; break; } if ((!isDisHtml5 && flObject.major == 0) || isHtml5) { zm('#oplayer').remove(); zm('#_htmlPlayer').removeClass('none'); var HTML5_SKIN = 'skins/jplayer_01'; document.write('<link href=\"http://static.mp3.zdn.vn/' + HTML5_SKIN + '/css/skin.css\" rel=\"stylesheet\" type=\"text/css\" />'); zmCore.addScript('http://static.mp3.zdn.vn/' + HTML5_SKIN + '/js/jquery.min.js', function () { zmCore.addScript('http://static.mp3.zdn.vn/' + HTML5_SKIN + '/js/jquery.jplayer.min.js', function () { $(\"#jquery_jplayer_1\").jPlayer({ ready: function () { $(this).jPlayer(\"setMedia\", { mp3: \"[http://mp3.zing.vn/html5/song/LHcnypFzWANATyDGkH][1]\" }); $(this).jPlayer(\"play\"); }, solution: \"html\", supplied: \"mp3\" }); }); }); } </script>";

Document doc = Jsoup.parse(html);
Elements elements = doc.select("script");
ListIterator<Element> iter = elements.listIterator();
while(iter.hasNext()) {
Element el = iter.next();
if(el.tagName().equalsIgnoreCase(Tag.SCRIPT.toString())) {
Matcher matcher = pattern.matcher(el.html());
while (matcher.find()) {
System.out.println(matcher.group(1));
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

关于javascript - 在 JavaScript 中为 jsoup 设置 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25966097/

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