问题描述
我试图在没有成功的情况下访问数据我尝试了我找到的所有文档但没有成功希望得到天才的帮助...
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)
}
}
)
希望得到帮助来访问这个对象...
解决方法
只需在整个响应中使用正则表达式:
json = html.match(/window.appConfig = (\{.*\})/)[1]