Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: Get "raw" html document from website

Tags:

html

flutter

I am fairly new to (flutter) development and I have a question:

There is this website, and I would like to display the content in an app. As far as I understood the website, it is an server-site html render. Since there are no API's (atleast I didn't find them) which I can use to read the data, I wanted to get the whole html document and parse all of the "interesting" data out.

Do you have any idea how I get the html document so that I can start parsing? Or is there a more elegant solution to my problem?

Info: I don't want to make a html render, I have build my own UI and just want to insert specific data

Thanks a lot in advance!

like image 201
Aleksandar Jovanovic Avatar asked Apr 24 '26 17:04

Aleksandar Jovanovic


1 Answers

I've just tested an http.get request on Flutter to the url you specified and works well. I used this package to make the get request, I defined an async funcion to make the request and in the main function of a Flutter app I call that function:

//This import the package
import 'package:http/http.dart' as http;

//...
//Here comes code of Flutter
//...

//Now I define the async function to make the request
void makeRequest() async{
    var response = await http.get('https://speiseplan.app.itelligence.org/');
    //If the http request is successful the statusCode will be 200
    if(response.statusCode == 200){
      String htmlToParse = response.body;
      print(htmlToParse);
    }
}

//...
//Here comes more Flutter code
//...

main(){
    makeRequest();
}

This will print the html you want, as String and now you can parse it as you want.

like image 53
Ademir Villena Zevallos Avatar answered Apr 27 '26 07:04

Ademir Villena Zevallos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!