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

Categories

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

web scraping - 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)
    }
  }
)

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

1 Answer

0 votes
by (71.8m points)

Just use regex on the whole response:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...