dqrqp8492 2016-07-28 10:47
浏览 29
已采纳

Golang http。获取块资源

How can I use Golang's net/http's http.Get(url string) but block certain url's and resources from request?

E.g.

http.Get("https://google.com") // But somehow block the main CSS file.
  • 写回答

1条回答 默认 最新

  • douhuifen9942 2016-07-28 15:15
    关注

    You do not need to block URLs and resources because net/http Get() will not automatically perform fetching of included links or resources.

    You probably confuse it with how a browser fetches a URL. A browser will issue a request and then follow up with fetching all the resources (Javascript/CSS/images/videos etc.) But Go's net/http request is much lower level - it is more like curl fetch - it will follow redirect by default, but otherwise it will just fetch a single response to the GET request. You can think of the result of issuing a call `http.Get("https://google.com") as similar to what you see as in the browser as the page source (plus HTTP headers and response code). This response will likely to include a number of other URLs for links and resources - if you like, you can parse them out and request some or all of them (leaving out what you would want to "block"), like low-level web crawlers do.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程