6

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?

Thanks

2 Answers 2

11

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

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

See overload method #3:

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

Note: Cross domain requests for GET are subject to CORS

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, got it working with that plus using a cors proxy
0

Working Example

service.ts

  getRawData(): Observable<any> {
    const api = 'https://www.w3.org/TR/PNG/iso_8859-1.txt';
    return this.httpClient.get(api,{ responseType: 'text' });    
  }

component.ts

import { Component, OnInit } from '@angular/core';

import { HttpClient } from '@angular/common/http';
import { AppService } from './app.service';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent implements OnInit {
  name = 'Angular 5';
  rawlist: any;

  constructor(private appService: AppService) {}

  ngOnInit() {}

  getRawData() {
    this.appService
      .getRawData()
      .subscribe(
        data => this.rawlist=data,
        error => console.log(error)
      );
  }

}

.html

<button (click)="getRawData()">get raw data </button>

 {{rawlist }}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.