在JavaScript中为jsoup设置url

set url in JavaScript for jsoup

本文关键字:设置 url jsoup 中为 JavaScript      更新时间:2023-09-26

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