1

So I'm trying to get data from my script tag HTML with cheerio

here is my scripttag.html :

<html>
<head>
    <script type="text/javascript">
    var playerInstance=jwplayer('smthing');
    playerInstance.setup(
        {
        title : '',
        tracks: [{
            file: '',
            kind: 'captions',
            'default': true
        }],
        sources: [{'file':'vidurl','type':'video/mp4'}],
        image: "imageurl",
        captions:
            {
            color:'#FFFF00',fontSize:17,backgroundOpacity:50
        },
    }
    );
    </script>
</head>
</html>

Im using Cheerio To load the html but... how do i really get the vidurl ?

here is my index.js:

const html = ("the scripttag.html")

    const cheerio = require("cheerio");


    let $ = cheerio.load(html)
const scripttag = $.html("head > script")

const title = ...
const srcfiles = ...
const image = ...

Now I got the script tag, but how do I get the

const title from playerintance.setup -> title

const srcfiles from playerinstance.setup -> sources -> file

const image from playerinstance.setup -> image

MoonL
  • 21
  • 3
  • 1
    That's not possible with cheerio since it just scraps the site as plain text basically. Thus, the JS within the ` – NullDev Feb 08 '21 at 12:00

1 Answers1

0

You would use regex for that:

html.match(/\{'file':'(.*?)'/)[1]
pguardiario
  • 53,827
  • 19
  • 119
  • 159