用phantom抓取百度云分享为什么抓取不了动态生成的分享内容?

我想学一下phantomjs,用node的phantom模块。
我用百度云分享来测试
原网页时有分享内容的

clipboard.png
我用phantom来加载后显示到页面中,却看不到分享内容

clipboard.png

(async function () {
  const instance = await phantom.create()
  const page = await instance.createPage()
  await page.on('onResourceRequested', function (requestData) {
    console.info('Requesting', requestData.url)
  })

  const status = await page.open('https://pan.baidu.com/share/home?uk=4197889247&suk=dnExnttUMb_71obP9h5jSg#category/type=0')
  const content = await page.property('content')
  const evaluate = await page.evaluate(function () {
    return document.body.innerHTML
  })
  console.log(evaluate)  //输出到浏览器
  console.log(content)  //或者这个输出到浏览器
  await instance.exit()
})()

我是用koa做服务器,将解析的代码放到浏览器看的,输出没有分享的内容。
请问这是为什么?

阅读 3.3k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题