小编luk*_*luk的帖子

Puppeteer 获取在新选项卡中打开的网页的 url

我正在编写一个网络爬虫来验证体育赛事的日期。一个网站没有在列表中显示体育赛事网址,而是像这样的链接:www.domain.com/redirectsystem/id12345等,一旦单击,就会打开该赛事网站的新选项卡。我想要实现的是获取在新选项卡中打开的该网站的网址。

我已设法单击 puppeteer 的链接,网站正在新选项卡中打开,但我不知道如何获取 url 信息

 const browser = await puppeteer.launch({
   headless: false,
   'args' : [
          '--no-sandbox',
          '--disable-setuid-sandbox'
        ]
  });

  const newPagePromise = new Promise(x => browser.once('targetcreated', target => x(target.page())));
      await page.click('span.link-hightlight');

      const newPage = await newPagePromise; 
      const url = await newPage.url() // this is not working 
      console.log(url) 
Run Code Online (Sandbox Code Playgroud)

node.js puppeteer

11
推荐指数
2
解决办法
1万
查看次数

Nextjs 13+ 元数据和页面数据双重获取

我有简单的 next js 应用程序和应用程序路由器 NextJS13+。我完全按照文档中的方式使用动态元数据。

import { Metadata, ResolvingMetadata } from 'next'

type Props = {
  params: { id: string }
 searchParams: { [key: string]: string | string[] | undefined }
}

export async function generateMetadata(
 { params, searchParams }: Props,
 parent: ResolvingMetadata
): Promise<Metadata> {
 // read route params
 const id = params.id

 // fetch data
const product = await fetch(`https://.../${id}`).then((res) => res.json())

// optionally access and extend (rather than replace) parent metadata
const previousImages = (await parent).openGraph?.images || …
Run Code Online (Sandbox Code Playgroud)

reactjs next.js

3
推荐指数
1
解决办法
1530
查看次数

标签 统计

next.js ×1

node.js ×1

puppeteer ×1

reactjs ×1