LearningReact
LearningReact

Reputation: 113

Cheerio Access an object in a script tag Node.js

I'm trying to access the data in a without success I tried all the documentation that I found without success hope for help from a genius ...

request(
  "https://www.answers.com/Q/What_are_examples_of_prefixes_and_suffixes",
  (error, response, html) => {
    if (!error && response.statusCode == 200) {
      let $ = cheerio.load(html)
      // here what can i do to find the data for the <script>
      console.log((str = $("script")[0].children[0].data))
      console.log("Scraping Done...")
    } else {
      console.log("Scrapping Failed")
      console.log(error)
    }
  }
)

script tag

hope for help to access this object...

Upvotes: 2

Views: 377

Answers (1)

pguardiario
pguardiario

Reputation: 54984

Just use regex on the whole response:

json = html.match(/window.appConfig = (\{.*\})/)[1]

Upvotes: 2

Related Questions