admin管理员组文章数量:1323330
I am using the $http.get('url') to get the content present in the 'url' present. The html in 'url' is as follows
<html>
<head></head>
<body>
<pre style = "word-wrap: break-word; white-space: pre-wrap;">
<!-- content is present here -->
</pre>
</body>
</html>
When I make a $http.get to this url, I get some data and the required content
GET /TYPE=abvd HTTP 1.1
content required
.0.1234.123 Safari /123.12
Referer: //url of the webpage calling this function
Accept-Encoding:
...............
How do I get rid of this extra information and receive only the content? (I know we can just parse the response but is there a better way of doing it? )
EDIT: The data response I got was seen in google chrome, when I run the same script in IE10, I get the only the "html content" as desired. Why does this difference occur and how do I make process it?
I am using the $http.get('url') to get the content present in the 'url' present. The html in 'url' is as follows
<html>
<head></head>
<body>
<pre style = "word-wrap: break-word; white-space: pre-wrap;">
<!-- content is present here -->
</pre>
</body>
</html>
When I make a $http.get to this url, I get some data and the required content
GET /TYPE=abvd HTTP 1.1
content required
.0.1234.123 Safari /123.12
Referer: //url of the webpage calling this function
Accept-Encoding:
...............
How do I get rid of this extra information and receive only the content? (I know we can just parse the response but is there a better way of doing it? )
EDIT: The data response I got was seen in google chrome, when I run the same script in IE10, I get the only the "html content" as desired. Why does this difference occur and how do I make process it?
Share edited Jun 17, 2015 at 9:05 clearScreen asked Jun 17, 2015 at 6:40 clearScreenclearScreen 1,0124 gold badges15 silver badges31 bronze badges 2- 2 those are response headers which will e with all http requests... you can modify your server response to change them... but they are harmless and you really don't have to worry about them – Arun P Johny Commented Jun 17, 2015 at 6:43
- i might not be able to modify the server response. – clearScreen Commented Jun 17, 2015 at 8:18
1 Answer
Reset to default 3$http.get
returns an HttpPromise, and from it you can get the underlying data like so:
$http.get('url').then(function(response) {
html = response.data;
});
To get even more useful data, you can expand this like so:
$http.get('url').then(
// success handler
function(response) {
var data = response.data,
status = response.status,
header = response.header,
config = response.config;
},
// error handler
function(response) {
var data = response.data,
status = response.status,
header = response.header,
config = response.config;
});
Demo: JSBin
Edit: If there are still HTML issues, you can look into $sce.trustAsHtml(html)
or PhantomJS with references:
- Parse an HTML document with AngularJS
- Scraping an AngularJS application
本文标签: javascriptgetting the html content of the url specified in AngularJSStack Overflow
版权声明:本文标题:javascript - getting the html content of the url specified in AngularJS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742139921a2422535.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论