我正在使用Google Apps脚本发出一系列HTTP请求。我一直使用的端点刚刚切换到了基于指针的分页。
响应如下所示。
{...
Link=
<https://x.shopify.com/admin/api/2019-10/inventory_levels.json?limit=250&page_info=abc>;rel="previous",
<https://x.shopify.com/admin/api/2019-10/inventory_levels.json?limit=250&page_info=def>;rel="next"
}我可以使用response['Link']将其精确到
<https://x.shopify.com/admin/api/2019-10/inventory_levels.json?limit=250&page_info=abc>;rel="previous",
<https://x.shopify.com/admin/api/2019-10/inventory_levels.json?limit=250&page_info=def>;rel="next"有没有一种方法可以在不使用正则表达式的情况下可靠地从"next" URL中提取page_info?我可以求助于正则表达式,但我想知道是否有特定的方法来获得它。
提前感谢您的帮助。我涉猎了一下,我知道我还有很多东西要学。
发布于 2021-08-11 08:31:14
您可以使用正则表达式来提取URL以及链接是下一页还是上一页。
/<(.*)>; rel=\"(.*)\"/要对你的代码使用它,你可以这样做:
const urls = headers.links.map(link => {
const linkContents = link.match(/<(.*)>; rel=\"(.*)\"/)
const url = linkContents[1]
const type = linkContents[2] // next or previous
return { url, type }
})https://stackoverflow.com/questions/59337670
复制相似问题