【问题标题】:send get request and get html as response发送获取请求并获取 html 作为响应
【发布时间】:2020-10-05 07:42:43
【问题描述】:

我想使用 axios 发送 get 请求并获取 url html 源 代码作为响应 iam 使用 reactjs 并使用 axios 包发送 获取请求,但它没有按预期工作。我想要的底线 发送获取请求并获取响应,如下图所示。

这是我试图使其工作的代码:

axios.get('https://www.google.com/').then((res)=>{
     console.log(res.data)
   })

click to see the image

【问题讨论】:

  • 有什么问题?说明没有按预期工作

标签: html node.js reactjs web-scraping axios


【解决方案1】:

首先要知道,axios GET 请求返回的是一些数据,而不是源代码。

由于不能渲染 HTML,postman 会显示源代码。

所以你只能向返回一些数据的 URL 发出 GET 请求

【讨论】:

  • 那么我如何发送获取请求并获取 html 作为响应?我使用带有axios的cheerio库解决了这个问题
猜你喜欢
  • 1970-01-01
  • 2011-12-21
  • 1970-01-01
  • 1970-01-01
  • 2011-07-06
  • 2019-02-23
  • 1970-01-01
  • 1970-01-01
  • 2023-02-01
相关资源
最近更新 更多