Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
231 views
in Technique[技术] by (71.8m points)

javascript - Parsing JS with Python Beautifulsoup

I have some page parsed with beautiful soup. I want to get "http://daohuolab.oss-cn-beijing.aliyuncs.com/dd/8525_92433.m4a".

How can I get the values from this input?

Thanks

<script>
    var ap = new APlayer({
                element: document.getElementById("player"),
                narrow: !1,
                autoplay: !1,
                theme: "#ffa42f",
                music: {
                    title: "212121",
                    author: "a",
                    url: "http://daohuolab.oss-cn-beijing.aliyuncs.com/dd/8525_92433.m4a",
                    pic: "https://s1.aaaax1x.com/2020/06/13/tj1eln.png"
                                    }
            }),
            as = $("#as-con"),
            mask = $("#as-mask");
    function hideActionSheet() {
        as.removeClass("weui-actionsheet_toggle"),
                mask.hide()
    }
    mask.on("click", hideActionSheet),
            $("#as-cancel").on("click", hideActionSheet),
            $("#speed-control-tab").on("click", function() {
                as.addClass("weui-actionsheet_toggle"),
                        mask.show()
            }),
            $(".speed-item").on("click", function() {
                var e = $(this).data("v");
                ap.audio.playbackRate = e,
                        $("#speed-control-tab").find("p").html(e + "x"),
                        $(".speed-item").removeClass("ycolor"),
                        $(this).addClass("ycolor"),
                        hideActionSheet()
            });
</script>]
question from:https://stackoverflow.com/questions/65840327/parsing-js-with-python-beautifulsoup

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

you can use regular to matching

>>> import re 
>>> js_html = '''<script>
    var ap = new APlayer({
                element: document.getElementById("player"),
                narrow: !1,
                autoplay: !1,
                theme: "#ffa42f",
                music: {
                    title: "212121",
                    author: "a",
                    url: "http://daohuolab.oss-cn-beijing.aliyuncs.com/dd/8525_92433.m4a",
                    pic: "https://s1.aaaax1x.com/2020/06/13/tj1eln.png"
                                    }
            }),
            as = $("#as-con"),
            mask = $("#as-mask");
    function hideActionSheet() {
        as.removeClass("weui-actionsheet_toggle"),
                mask.hide()
    }
    mask.on("click", hideActionSheet),
            $("#as-cancel").on("click", hideActionSheet),
            $("#speed-control-tab").on("click", function() {
                as.addClass("weui-actionsheet_toggle"),
                        mask.show()
            }),
            $(".speed-item").on("click", function() {
                var e = $(this).data("v");
                ap.audio.playbackRate = e,
                        $("#speed-control-tab").find("p").html(e + "x"),
                        $(".speed-item").removeClass("ycolor"),
                        $(this).addClass("ycolor"),
                        hideActionSheet()
            });
</script>]'''

>>> res = r'url: "(.*?)"'
>>> surls = re.findall(res, js_html)
>>> surls
['http://daohuolab.oss-cn-beijing.aliyuncs.com/dd/8525_92433.m4a']

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...