Search
 
SCRIPT & CODE EXAMPLE
 

HTML

flutter html parser

import 'package:html/parser.dart' show parse;

main(List<String> args) {
  parseData();
}

parseData(){
  var document = parse("""
    <div class="weather-item now"><!-- now  -->
   <span class="time">Now</span>
   
    <div class="temp">19.8<span>℃</span>
        <small>(23℃)</small>
    </div>
   
   <table>
       <tr>
           <th><i class="icon01" aria-label="true"></i></th>
           <td>93%</td>
       </tr>
       <tr>
           <th><i class="icon02" aria-label="true"></i></th>
           <td>south 2.2km/h</td>
       </tr>
       <tr>
           <th><i class="icon03" aria-label="true"></i></th>
           <td>-</td>
       </tr>
   </table>
</div>
  """);

  //declaring a list of String to hold all the data.
  List<String> data = [];

  data.add(document.getElementsByClassName("time")[0].innerHtml);

  //declaring variable for temp since we will be using it multiple places
  var temp  = document.getElementsByClassName("temp")[0];
  data.add(temp.innerHtml.substring(0, temp.innerHtml.indexOf("<span>")));
  data.add(temp.getElementsByTagName("small")[0].innerHtml.replaceAll(RegExp("[(|)|℃]"), ""));

  //We can also do document.getElementsByTagName("td") but I am just being more specific here.
  var rows = document.getElementsByTagName("table")[0].getElementsByTagName("td");

  //Map elememt to its innerHtml,  because we gonna need it. 
  //Iterate over all the table-data and store it in the data list
  rows.map((e) => e.innerHtml).forEach((element) {
    if(element != "-"){
      data.add(element);
    }
  });

  //print the data to console.
  print(data);
  
}
Comment

flutter html parser

#Here is a stackoverflow thread that might help:

https://stackoverflow.com/questions/62577610/how-can-i-parse-html-in-flutter
Comment

PREVIOUS NEXT
Code Example
Html :: jspdf html to pdf angular 8 
Html :: shopify liquid for loop 
Html :: http code 206 
Html :: html text 
Html :: sample code html header template code 
Html :: google material icons 
Html :: html frame 
Html :: jinja check if variable is none 
Html :: require is not define on html script 
Html :: run script after html load 
Html :: text-muted 
Html :: html table serial number 
Html :: how to resize submit button in html 
Html :: html input type="color" 
Html :: express js search example 
Html :: run html 
Html :: all meta og tags 
Html :: display observable in html angular 
Html :: how to auto fit image in div 
Html :: ## File * [random-numbers-unsolved](Unsolved/random-numbers-unsolved.html) ### Instructions * Research how to improve on Math.random() to generate a random whole number between 1 and 10 instead of a random decimal number 
Html :: Two way binding html templatevue js 
Html :: 38 1,2 
Html :: jqery each from string html 
Html :: remove autocomplete 
Html :: html content editable no newline 
Html :: Rendering text in italics in HTML 
Html :: mimekit email body base64 image in the body 
Html :: show image inside table with innerhtml 
Html :: Style 
Html :: constellation css 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =