scinfu/SwiftSoup

How to get js element?

anisbouziane opened this issue · 1 comments

Hi,

How to get the url of mp4 file in this element :

<script type="text/javascript"> jwplayer.key="key=="; jwplayer('player').setup({ flashplayer:"jwplayer.flash.swf", html5player:"jwplayer.html5.js", provider: "video", type: 'mp4', file: 'http://example.com/file.mp4', startparam:'start', image: 'image.jpg', width: '100%', aspectratio: '4:3', allowscriptaccess:'always', wmode:'transparent', }); var videoSection = document.getElementById('player'); var videoElement = document.createElement('video'); var support = videoElement.canPlayType('video/mp4'); if (videoElement) { while (videoSection.hasChildNodes()) videoSection.removeChild(videoSection.firstChild); videoElement.setAttribute("crossorigin", ""); videoSection.appendChild(videoElement); } videoElement.play(); </script>

Hi try this but you need a regex to find your text.

let doc: Document = try! SwiftSoup.parse(h)
let ems = try doc.getElementsByTag("script").first()
for e in ems?.dataNodes() ?? [] {
let txt = e.getWholeData()
      //here yuo need a RegEx
      print(txt)
}