Javascript 如何在Node.js中获取完整URL?

Javascript 如何在Node.js中获取完整URL?,javascript,node.js,url,puppeteer,Javascript,Node.js,Url,Puppeteer,我有一个网址https://twitter.com/Javeria85685955/status/1059335612346650624 我想在运行时获取Node.js中的完整url。我用的是木偶师刮削 我的代码是: 它给我的输出如下: 这是一个完整的URL: { "protocol": null, "slashes": null, "auth": null, "host": null, "port": null, "hostname": null

我有一个网址https://twitter.com/Javeria85685955/status/1059335612346650624 我想在运行时获取Node.js中的完整url。我用的是木偶师刮削

我的代码是:

它给我的输出如下:

这是一个完整的URL:

{
    "protocol": null,
    "slashes": null,
    "auth": null,
    "host": null,
    "port": null,
    "hostname": null,
    "hash": null,
    "search": null,
    "query": {},
    "pathname": "/",
    "path": "/",
    "href": "/"
}
但我需要的输出是:

试试这个:

const myURL = req.headers.referer;
如果您使用的是Puppeter,那么为什么不利用Puppeter API检索URL,如下所示:

const url = await page.url();
console.log(url); // This will output the current URL to the console

对我来说似乎是最简单的解决方案?

什么是req.url?输出表明它是空的。我不知道你怎么期望一台计算机能够从一无所有变成twitter.com上的URL。你是twitter开发人员吗?它来自回调函数我是nodejs开发人员。我想在运行时获取URL。我使用的是puppeter nodejs模块。它返回的结果与以前相同。尝试从req.URL获取主机名表单req.headers.host和URL游戏我只基地网址。在example.com中,与example.com/thisismy.html相对@AJC24
const url = await page.url();
console.log(url); // This will output the current URL to the console