Kullakitab

 



gethttp() async {
    print('http called');

    for (var i = 0; i < datas![0].chapters!.length; i++) {
      final linke =
          Uri.parse(SCRAP_URL + datas![0].chapters![i].link!.toString());
      final respone = await http.get(linke);

      if (respone.statusCode == 200) {
        dom.Document html = dom.Document.html(respone.body);
        final titles = html
            .querySelectorAll(
                '#content > div > div.row-offcanvas.row-offcanvas-left > div > div.col-xs-12.col-sm-9 > div > div > div.row > div > a')
            .map((element) => element.innerHtml.trim())
            .toList();

        final urls = html
            .querySelectorAll(
                '#content > div > div.row-offcanvas.row-offcanvas-left > div > div.col-xs-12.col-sm-9 > div > div > div.row > div > a')
            .map((element) =>
                'http://www.khullakitab.com/${element.attributes['href']}')
            .toList();
        dev.log(titles.length.toString());
        for (var j = 0; j < titles.length; j++) {
          var linkee = Uri.parse(urls[j]);
          final responee = await http.get(linkee);

          dom.Document htmle = dom.Document.html(responee.body);
          var mm = htmle
              .querySelector(
                  '#content > div > div.row-offcanvas.row-offcanvas-left > div > div.col-xs-12.col-sm-9 > div > div ')!
              .innerHtml;

          dom.Document htmla = dom.Document.html(mm);
          var datase = htmla
              .getElementsByClassName("col-xs-12")[titles.length + 2]
              .innerHtml;
          Directory? dir = await getExternalStorageDirectory();
          var filee = File('${dir!.path}/${titles[j]}.json');

          var myap = {
            "title": datas![0].chapters![i].name,
            "data": base64.encode(utf8.encode(datase))
          };
          await filee.writeAsString(jsonEncode(myap));
          dev.log('${dir.path}/${titles[j]}.json');
        }
      }
    }
  
}




 getexc() async {
    print('http called');
    List Chap = [];
    var aam = {"year": "Revised Year 2077", "chapters": Chap};
    for (var i = 0; i < datas![0].chapters!.length; i++) {
      final linke =
          Uri.parse(SCRAP_URL + datas![0].chapters![i].link!.toString());
      final respone = await http.get(linke);

      if (respone.statusCode == 200) {
        dom.Document html = dom.Document.html(respone.body);
        final titles = html
            .querySelectorAll(
                '#content > div > div.row-offcanvas.row-offcanvas-left > div > div.col-xs-12.col-sm-9 > div > div > div.row > div > a')
            .map((element) => element.innerHtml.trim())
            .toList();

        final urls = html
            .querySelectorAll(
                '#content > div > div.row-offcanvas.row-offcanvas-left > div > div.col-xs-12.col-sm-9 > div > div > div.row > div > a')
            .map((element) =>
                'http://www.khullakitab.com/${element.attributes['href']}')
            .toList();

        var myapa = {
          "name": datas![0].chapters![i].name!.toString(),
          "link": "",
          "direct": false,
          "exc": List.generate(titles.length, (index) {
            return {
              "name": titles[index].toString(),
              "type": "BASE",
              "link": titles[index].toString()
            };
          })
        };

        Chap.add(myapa);
      }
    }
    dev.log(jsonEncode(aam));
  }  
    
  
    getnotes() async {
    final link = Uri.parse(
        'http://www.khullakitab.com/permutation-and-combination/notes/mathematics/grade-12/29/notes');

    final respone = await http.get(link);

    if (respone.statusCode == 200) {
      dom.Document html = dom.Document.html(respone.body);
      var mm = html
          .querySelectorAll(
              '#content > div > div.row-offcanvas.row-offcanvas-left > div > div.col-xs-6.col-sm-3.sidebar-offcanvas.sidebar-nav.no-margin > ul > li > h3 > a')
          .map((element) =>
              'http://www.khullakitab.com/${element.attributes['href']}')
          .toList();
      var mam = html
          .querySelectorAll(
              '#content > div > div.row-offcanvas.row-offcanvas-left > div > div.col-xs-6.col-sm-3.sidebar-offcanvas.sidebar-nav.no-margin > ul > li > h3 > a')
          .map((element) => element.innerHtml.trim())
          .toList();
      Directory? dir = await getExternalStorageDirectory();

      // var sss = List.generate(mm.length,
      //     (index) => {"name": mam[index], "type": "BASE", "link": mam[index]});

      // dev.log(jsonEncode(sss));
      for (var i = 0; i < mm.length; i++) {
        Uri linkee;
        if (i == 0) {
          linkee = Uri.parse(
              'http://www.khullakitab.com/permutation-and-combination/notes/mathematics/grade-12/29/notes');
        } else {
          linkee = Uri.parse(mm[i].toString());
        }

        final responee = await http.get(linkee);

        dom.Document htmle = dom.Document.html(responee.body);
        var mm2 = htmle
            .querySelector(
                '#content > div > div.row-offcanvas.row-offcanvas-left > div > div.col-xs-12.col-sm-9 > div > div ')!
            .innerHtml;
        print(mm2.toString());
        dom.Document htmla = dom.Document.html(mm2);
        var ggg = htmla.getElementsByClassName("col-xs-12")[2].innerHtml;

        var filee = File('${dir!.path}/${mam[i]}.json');

        var myap = {"data": base64.encode(utf8.encode(ggg))};
        await filee.writeAsString(jsonEncode(myap));
        dev.log('${dir.path}/${mam[i]}.json');
      }
    }
    setState(() {});
  }

  

Post a Comment

Previous Post Next Post