Advertisement
faber001

Dart3

Mar 11th, 2020
472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.35 KB | None | 0 0
  1. import 'package:http/http.dart';
  2. import 'package:html/dom.dart' show Document;
  3. import 'package:html/parser.dart' show parse;
  4. https://vm.tiktok.com/78Dc1Y/?utm_source=copy_link&utm_campaign=client_share&utm_medium=android&share_app_name=musically&share_iid=6817857825445332741
  5. class Fetch {
  6.   Request rek;
  7.   String mth;
  8.   bool follow;
  9.   Map<String, String> body;
  10.   Map<String, String> header = {
  11.     'User-Agent':
  12.         'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36',
  13.     'Content-Type': 'application/x-www-form-urlencoded'
  14.   };
  15.  
  16.   Fetch(this.mth, {header, this.body, this.follow: false}) {
  17.     if (header != null) this.header.addAll(header);
  18.  
  19.     rek = Request(
  20.         mth, Uri.parse('http:/'));
  21.     rek.headers.addAll(this.header);
  22.     //rek.followRedirects = follow;
  23.   }
  24.  
  25.   Future<StreamedResponse> get sg => rek.send();
  26.  
  27.   Future<StreamedResponse> get sp => (rek
  28.         //..headers.addAll(header)
  29.         ..bodyFields = body)
  30.       .send();
  31.  
  32.   Future<StreamedResponse> send() {
  33.     if (mth == 'GET') return sg;
  34.     if (mth == 'POST') return sp;
  35.     throw 'Can\'t create $mth.';
  36.   }
  37. }
  38.  
  39. class DoLogin {
  40.   Map<String, String> pl = {'btEnt': 'Entra'};
  41.   String matricula;
  42.   String senha;
  43.  
  44.   DoLogin(this.matricula, this.senha);
  45.  
  46.   login() async {
  47.     print('dologin login');
  48.  
  49.     pl['txtTexto'] = matricula;
  50.  
  51.     await Fetch('GET').send().then((response) async {
  52.       await response.stream.bytesToString().then((rHtml) async {
  53.         Document document = parse(rHtml);
  54.         var p = document.getElementsByTagName("[name*='__']");
  55.         for (var i in p) {
  56.           pl[i.attributes['name']] = i.attributes['value'];
  57.         }
  58.         await Fetch('POST', body: pl).send().then((response2) async {
  59.           var cookie = {'Cookie': response2.headers['set-cookie']};
  60.           print(cookie);
  61.           await response2.stream.bytesToString().then((rHtml2) async {
  62.             var document2 = parse(rHtml2);
  63.             pl.clear();
  64.             pl.addAll({'btEnt': 'Entra', 'txtTexto': senha});
  65.             var p2 = document2.getElementsByTagName("[name*='__']");
  66.             for (var i in p2) {
  67.               pl[i.attributes['name']] = i.attributes['value'];
  68.             }
  69.  
  70.             var d2 = document2.querySelector("#lblMensagem");
  71.             print(d2.text);
  72.  
  73.             await Fetch('POST', body: pl, header: cookie, follow: true)
  74.                 .send()
  75.                 .then((response3) async {
  76.  
  77.                   print(response3.statusCode);
  78.                   print(response3.headers);
  79.  
  80.  
  81.  
  82.  
  83.               await response3.stream.bytesToString().then((rHtml3) {
  84.                 print(rHtml2);
  85.                 var document3 = parse(rHtml3);
  86.                 print(document3.body);
  87.                 var d3 = document3.querySelector("#lblMensagem");
  88.                 if (d3 != null) print(d3.text);
  89.  
  90.               });
  91.  
  92.             });
  93.           });
  94.         });
  95.       });
  96.     });
  97.   }
  98. }
  99.  
  100. main() {
  101.   DoLogin('456', '456').login();
  102. }
  103.  
  104.  
  105.  
  106.  
  107. import 'dart:async';
  108. import 'dart:io';
  109. import 'package:html/parser.dart' show parse;
  110.  
  111.  
  112. void main() {
  113.   new File('html.txt').readAsString().then((String contents) {
  114.     List lis = [];
  115.     var doc = parse(contents);
  116.     var tab = doc.querySelectorAll('#masterBody_dgPonto tr');
  117.     for(var i in tab) {
  118.       var cada = i.text.split('\n                ');
  119.       cada.removeAt(0);
  120.       lis.add(cada);
  121.     }
  122.     lis.removeLast();
  123.     print(lis);
  124.  
  125.   });
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement