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

查看:77
本文介绍了角http.get()网址为原始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

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

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