0

I have some page parsed with Beautiful Soup. I want to get "http://dm/dd/8525_92433.m4a", which is contained in a variable passed to a JavaScript on-click call.

How can I get the values from this input?

<script>
    var ap = new APlayer({
                element: document.getElementById("player"),
                narrow: !1,
                autoplay: !1,
                theme: "#ffa42f",
                music: {
                    title: "212121",
                    author: "a",
                    url: "http://m/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>]

1
  • Using Beautifulsoup, you can parse it as a string and use string methods, and parse it to a json, and work from there Commented Jan 22, 2021 at 6:35

1 Answer 1

1

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']
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.