首先,我为我的英语感到抱歉。我不是说母语的人,所以。我正在开发React Native上的一个新闻应用程序。为此,我在木偶剧上做了一个新闻采集器。问题出在iframe中。我拿不到。我尝试评估页面并使用querySelector。它找不到它。我该怎么办?我只想获得iframe内容或链接来显示它。
我想要抓取的页面- link
在那里,我需要取一个电报iframe。我已经成功地抓取它的标题,内容,文章照片等。所以,我只需要的代码为iframe抓取。
发布于 2021-06-06 08:21:11
这就是解决方案:
await page.goto(`https://sharij.net/lukashenko-my-ne-mozhem-stat-ukrainoj-i-voevat-protiv-rossii`, { waitUntil: 'networkidle0', timeout: 0 })
await page.waitForSelector("iframe[id^=telegram]")
await page.evaluate(() => {
const frameDocument = document.querySelector("iframe[id^=telegram]").contentWindow.document // this is the solution
const videoMessage = frameDocument.querySelector("div.tgme_widget_message") // just for checking that we can access elements
console.log(videoMessage.innerText)
// in same way you can get anything now from this iframe :)
})https://stackoverflow.com/questions/67841834
复制相似问题