Angular http.get() url 作为原始 HTML [英] Angular http.get() url as raw HTML

查看:22
本文介绍了Angular http.get() url 作为原始 HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为任务创建一个站点,我想在其中动态加载一些数据.问题是,数据只是来自网站,没有 API 或任何东西.有什么方法可以在 angular 中使用 http.get 将整个网站作为原始 HTML 提取,然后我可以解析这些信息以获取信息?

I'm creating a site for an assignment, where I want to dynamically load some data. Problem is, that data just comes from a website, no API or anything. Is there some way that I can use http.get in angular to pull the whole site as raw HTML, which I can then parse for info?

谢谢

推荐答案

您可以将 responseType 设置为 "text" 以获取字符串形式的响应.

You can set the responseType to "text" to fetch the response as a string.

this.httpClient.get(url, {responseType: "text"})

参见重载方法#3:

https://angular.io/api/common/http/HttpClient#get

注意:GET 的跨域请求受 CORS 约束

Note: Cross domain requests for GET are subject to CORS

这篇关于Angular http.get() url 作为原始 HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆