Node.js获取读取正文数据的请求

时间:2019-10-22 03:58:34

标签: node.js get request

这是我从请求获得响应的示例

Instant

我将如何提取底部的url,这只是实际请求正文中包含多个url的示例。

1 个答案:

答案 0 :(得分:1)

您可以通过正则表达式搜索并找到匹配的格式:

const urlRegex =/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/ig

// responseBodyText from the response you get
const matchedUrls = responseBodyText.match(urlRegex);

const extractedUrls = matchedUrls ? matchedUrls : []
// it should prints the all the urls on the response if there is any or empty array if not

示例与示例: enter image description here