insta_html_parser 0.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 63

Insta HTML Parser #

A package developed to retrieve data from Instagram profiles.
This should not be used for professional purposes.

If you really need this package you should take a look at the official Instagram API:
https://www.instagram.com/developer/

For more: example

https://github.com/GustavoContreiras/insta_html_parser
https://pub.dev/packages/insta_html_parser

[0.1.1] - 17/05/2019

  • Added static fields to get the last parsed informations.
InstaParser.lastPostsParsed; // returns List<String>
InstaParser.lastUserDataParsed; // returns Map<String, String>
InstaParser.lastPhotoUrlsParsed; // returns Map<String, String>
InstaParser.lastVideoUrlParsed; // returns String

[0.1.0] - 10/08/2019

  • Package ready to use
  • To do: improve performance of html tag searching

[0.0.5] - 10/08/2019

  • Improved description

[0.0.4] - 10/08/2019

  • Improved description
  • Used flutter format on lib/insta_html_parser.dart

[0.0.3] - 10/08/2019

  • Added one more method:
InstaParser.userDataFromProfile(String profileUrl);
  • Changed method names
InstaParser.postsUrlsFromProfile(String profileUrl);
InstaParser.photoUrlsFromPost(String postUrl);
InstaParser.videoUrlFromPost(String postUrl);
  • Implemented basic tests for all methods

  • Example app improved

[0.0.2] - 10/08/2019

  • Now it works with three static methods:
InstaParser.parsePostsUrlsFromInstaProfile(String profileUrl);
InstaParser.parsePhotosUrlsFromInstaPost(String postUrl);
InstaParser.parseVideoUrlFromInstaPost(String postUrl);

[0.0.1] - 05/08/2019

  • Made minimal version retrieving post and medias urls with an example app.

example/README.md

Insta HTML Parser Example #

An app developed to demonstrate how to use the insta_html_parser package.

Preview #

Example #

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:insta_html_parser/insta_html_parser.dart';

void main() {
  runApp(InstaParserExampleApp());
}

class InstaParserExampleApp extends StatefulWidget {
  final GlobalKey<ScaffoldState> scaffoldKey;
  InstaParserExampleApp({Key key, this.scaffoldKey}) : super(key: key);

  @override
  _InstaParserExampleAppState createState() => _InstaParserExampleAppState();
}

class _InstaParserExampleAppState extends State<InstaParserExampleApp> {
  var _scaffoldKey = new GlobalKey<ScaffoldState>();
  TextEditingController _profileUrlController = TextEditingController();
  TextEditingController _postUrlController = TextEditingController();
  TextStyle _textStyleBold = TextStyle(fontSize: 16.0, fontWeight: FontWeight.bold);
  TextStyle _textStyleUrl = TextStyle(fontSize: 16.0);
  List<Widget> _parsedWidgets = [];

  @override
  void initState() {
    super.initState();
    _profileUrlController.text = 'https://www.instagram.com/contreirasgustavo/';
    _postUrlController.text = 'https://www.instagram.com/p/BQQrPauBgvn/';
  }

  @override
  Widget build(BuildContext context) {

    return MaterialApp(
      color: Colors.blue,
      title: 'Insta HTML Parser',
      home: Scaffold(
        key: _scaffoldKey,
        backgroundColor: Colors.purple[100],
        appBar: AppBar(title: Text('Insta HTML Parser'), backgroundColor: Colors.purple[600],),
        body: Center(
          child: ListView(
            children: [
              
              Container( // Profile url input field
                padding: EdgeInsets.only(left: 16.0, right: 16.0, top: 16.0, bottom: 16.0),
                child: Form(
                  child: TextFormField(
                    controller: _profileUrlController,
                    decoration: InputDecoration(
                      contentPadding: EdgeInsets.only(top: 2.0, bottom: 2.0),
                      labelText: 'Profile URL', 
                      labelStyle: _textStyleUrl,
                      hintText: 'https://www.instagram.com/contreirasgustavo/',
                      hintStyle: TextStyle(color: Colors.grey[500], fontSize: 13)
                    )
                  )
                )
              ),

              Row(
                mainAxisSize: MainAxisSize.min,
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[

                  Container( // Profile avatar submit button
                    width: 160,
                    padding: EdgeInsets.only(left: 0.0, right: 0.0, bottom: 16.0),
                    child: RaisedButton(
                      child: Text('Get user data', style: _textStyleUrl,),
                      onPressed: () async {

                        List<Widget> _widgetsList = [];
                        Map<String, String> _userData = await InstaParser.userDataFromProfile('${_profileUrlController.text}');
                        
                        // Divider
                        _widgetsList.add(
                          Container(padding: EdgeInsets.only(top: 8.0, bottom: 8.0), 
                            child: Divider(height: 0.0, color: Colors.black)
                          )
                        );

                        // Is private?
                        _widgetsList.add(Text('Private profile?', style: _textStyleBold));
                        _widgetsList.add(Text('${_userData['isPrivate'] != null ? _userData['isPrivate'] : ''}', style: _textStyleUrl));

                        // Divider
                        _widgetsList.add(
                          Container(padding: EdgeInsets.only(top: 8.0, bottom: 8.0), 
                            child: Divider(height: 0.0, color: Colors.black)
                          )
                        );

                        // Is private?
                        _widgetsList.add(Text('Verified profile?', style: _textStyleBold));
                        _widgetsList.add(Text('${_userData['isVerified']  != null ? _userData['isVerified'] : ''}', style: _textStyleUrl));

                        // Divider
                        _widgetsList.add(
                          Container(padding: EdgeInsets.only(top: 8.0, bottom: 8.0), 
                            child: Divider(height: 0.0, color: Colors.black)
                          )
                        );

                        // Posts count
                        _widgetsList.add(Text('Posts count:', style: _textStyleBold));
                        _widgetsList.add(Text('${_userData['postsCount']  != null ? _userData['postsCount'] : ''}', style: _textStyleUrl));

                        // Divider
                        _widgetsList.add(
                          Container(padding: EdgeInsets.only(top: 8.0, bottom: 8.0), 
                            child: Divider(height: 0.0, color: Colors.black)
                          )
                        );

                        // Followers count
                        _widgetsList.add(Text('Followers count:', style: _textStyleBold));
                        _widgetsList.add(Text('${_userData['followersCount']  != null ? _userData['followersCount'] : ''}', style: _textStyleUrl));

                        // Divider
                        _widgetsList.add(
                          Container(padding: EdgeInsets.only(top: 8.0, bottom: 8.0), 
                            child: Divider(height: 0.0, color: Colors.black)
                          )
                        );

                        // Followings count
                        _widgetsList.add(Text('Followings count:', style: _textStyleBold));
                        _widgetsList.add(Text('${_userData['followingsCount']  != null ? _userData['followingsCount'] : ''}', style: _textStyleUrl));

                        // Divider
                        _widgetsList.add(
                          Container(padding: EdgeInsets.only(top: 8.0, bottom: 8.0), 
                            child: Divider(height: 0.0, color: Colors.black)
                          )
                        );

                        // Full name
                        _widgetsList.add(Text('Full name:', style: _textStyleBold));
                        _widgetsList.add(
                          GestureDetector(
                            child: Text('${_userData['fullName']  != null ? _userData['fullName'] : ''}', style: _textStyleUrl),
                            onTap: () async {
                              setState(() {});
                              Clipboard.setData(ClipboardData(text: '${_userData['fullName']}'));
                              _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("Copied full name")));
                            }
                          )
                        );

                        // Divider
                        _widgetsList.add(
                          Container(padding: EdgeInsets.only(top: 8.0, bottom: 8.0), 
                            child: Divider(height: 0.0, color: Colors.black)
                          )
                        );

                        // Username
                        _widgetsList.add(Text('Username:', style: _textStyleBold));
                        _widgetsList.add(
                          GestureDetector(
                            child: Text('${_userData['username'] != null ? _userData['username'] : ''}', style: _textStyleUrl),
                            onTap: () async {
                              setState(() {});
                              Clipboard.setData(ClipboardData(text: '${_userData['username']}'));
                              _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("Copied username")));
                            }
                          )
                        );

                        // Divider
                        _widgetsList.add(
                          Container(padding: EdgeInsets.only(top: 8.0, bottom: 8.0), 
                            child: Divider(height: 0.0, color: Colors.black)
                          )
                        );

                        // Biography
                        _widgetsList.add(Text('Biography:', style: _textStyleBold));
                        _widgetsList.add(
                          GestureDetector(
                            child: Text('${_userData['biography'] != null ? _userData['biography'] : ''}', style: _textStyleUrl,),
                            onTap: () async {
                              setState(() {});
                              Clipboard.setData(ClipboardData(text: '${_userData['biography']}'));
                              _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("Copied biography")));
                            }
                          )
                        );

                        // Divider
                        _widgetsList.add(
                          Container(padding: EdgeInsets.only(top: 8.0, bottom: 8.0), 
                            child: Divider(height: 0.0, color: Colors.black)
                          )
                        );

                        // Avatar photo url
                        _widgetsList.add(Text('Avatar photo:', style: _textStyleBold));
                        _widgetsList.add(
                          GestureDetector(
                            child: Text('${_userData['profilePicUrl'] != null ? _userData['profilePicUrl'] : ''}', style: _textStyleUrl,),
                            onTap: () async {
                              setState(() {});
                              Clipboard.setData(ClipboardData(text: '${_userData['profilePicUrl']}'));
                              _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("Copied profile pic url")));
                            }
                          )
                        );
                        if (_userData['profilePicUrl'] != null) {
                          _widgetsList.add(
                            Image.network('${_userData['profilePicUrl']}')
                          );
                        }                        

                        // Divider
                        _widgetsList.add(
                          Container(padding: EdgeInsets.only(top: 8.0, bottom: 8.0), 
                            child: Divider(height: 0.0, color: Colors.black)
                          )
                        );

                        // Avatar photo url hd
                        _widgetsList.add(Text('Avatar photo (HD):', style: _textStyleBold));
                        _widgetsList.add(
                          GestureDetector(
                            child: Text('${_userData['profilePicUrlHd'] != null ? _userData['profilePicUrlHd'] : ''}', style: _textStyleUrl,),
                            onTap: () async {
                              setState(() {});
                              Clipboard.setData(ClipboardData(text: '${_userData['profilePicUrlHd']}'));
                              _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("Copied profile pic url hd")));
                            }
                          )
                        );
                        if (_userData['profilePicUrlHd'] != null) {
                          _widgetsList.add(
                            Image.network('${_userData['profilePicUrlHd']}')
                          );
                        }                  
                        
                        _widgetsList.add(Padding(padding: EdgeInsets.only(bottom: 8.0),));
                      
                        setState(() => _parsedWidgets = _widgetsList);
                      }
                    ),
                  ),

                  Container( // Posts submit button
                    width: 128,
                    padding: EdgeInsets.only(left: 0.0, right: 0.0, bottom: 16.0),
                    child: RaisedButton(
                      child: Text('Get posts', style: _textStyleUrl,),
                      onPressed: () async {

                        List<Widget> _widgetsList = [];
                        List<String> _postsUrls = await InstaParser.postsUrlsFromProfile('${_profileUrlController.text}');
          
                        for (int i = 0; i < 12; i++) {

                          // Divider
                          _widgetsList.add(
                            Container(padding: EdgeInsets.only(top: 8.0, bottom: 8.0), 
                              child: Divider(height: 0.0, color: Colors.black)
                            )
                          );

                          // Post URL
                          _widgetsList.add(Text('Post ${i+1}:', style: _textStyleBold));
                          _widgetsList.add(
                            GestureDetector(
                              child: Text('${_postsUrls.length > 0 ? _postsUrls[i] : ''}', style: _textStyleUrl,),
                              onTap: () async {
                                setState(() {});
                                Clipboard.setData(ClipboardData(text: '${_postsUrls[i]}'));
                                _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("Copied post url")));
                              }
                            )
                          );

                          if (i == _postsUrls.length-1) {
                            _widgetsList.add(Padding(padding: EdgeInsets.only(bottom: 8.0),));
                          }
                        }

                        if (_postsUrls != null) {
                          if (_postsUrls.length > 0) {
                            setState(() {
                              _postUrlController.text = _postsUrls[1];
                              _parsedWidgets = _widgetsList;
                            });
                          }
                        } else {
                          setState(() => _parsedWidgets = _widgetsList);
                        }
                      }
                    ),
                  ),

                ],
              ),

              Container( // Post url input field
                padding: EdgeInsets.only(left: 16.0, right: 16.0, top: 16.0, bottom: 16.0),
                child: Form(
                  child: TextFormField(
                    controller: _postUrlController,
                    decoration: InputDecoration(
                      contentPadding: EdgeInsets.only(top: 2.0, bottom: 2.0),
                      labelText: 'Post URL', 
                      labelStyle: _textStyleUrl,
                      hintText: 'https://www.instagram.com/p/BQQrPauBgvn/',
                      hintStyle: TextStyle(color: Colors.grey[500], fontSize: 13)
                    )
                  )
                )
              ),

              Row( // Photos and video submit button 
                mainAxisSize: MainAxisSize.min,
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[

                  Container( // Parse photos
                    width: 160,
                    padding: EdgeInsets.only(left: 0.0, right: 0.0, bottom: 16.0),
                    child: RaisedButton(
                      child: Text('Get photos', style: _textStyleUrl,),
                      onPressed: () async {

                        List<Widget> _widgetsList = [];
                        Map<String, String> photosUrls = await InstaParser.photoUrlsFromPost('${_postUrlController.text}');

                        // Divider
                        _widgetsList.add(
                          Container(padding: EdgeInsets.only(top: 8.0, bottom: 8.0), 
                            child: Divider(height: 0.0, color: Colors.black)
                          )
                        );

                        // Small photo URL
                        _widgetsList.add(Text('Small photo:', style: _textStyleBold));
                        _widgetsList.add(
                          GestureDetector(
                            child: Text('${photosUrls['small'] != null ? photosUrls['small'] : ''}', style: _textStyleUrl,),
                            onTap: () async {
                              setState(() {});
                              Clipboard.setData(ClipboardData(text: '${photosUrls['small']}'));
                              _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("Copied small size photo url")));
                            }
                          )
                        );
                        if (photosUrls['small'] != null) {
                          _widgetsList.add(
                            Image.network(photosUrls['small'])
                          );
                        }

                        // Divider
                        _widgetsList.add(
                          Container(padding: EdgeInsets.only(top: 8.0, bottom: 8.0), 
                            child: Divider(height: 0.0, color: Colors.black)
                          )
                        );

                        // Medium photo URL
                        _widgetsList.add(Text('Medium photo:', style: _textStyleBold));
                        _widgetsList.add(
                          GestureDetector(
                            child: Text('${photosUrls['medium'] != null ? photosUrls['medium'] : ''}', style: _textStyleUrl,),
                            onTap: () async {
                              setState(() {});
                              Clipboard.setData(ClipboardData(text: '${photosUrls['medium']}'));
                              _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("Copied medium size photo url")));
                            }
                          )
                        );
                        if (photosUrls['medium'] != null) {
                          _widgetsList.add(
                            Image.network(photosUrls['medium'])
                          );
                        }

                        // Divider
                        _widgetsList.add(
                          Container(padding: EdgeInsets.only(top: 8.0, bottom: 8.0), 
                            child: Divider(height: 0.0, color: Colors.black)
                          )
                        );

                        // Large photo URL
                        _widgetsList.add(Text('Large photo:', style: _textStyleBold));
                        _widgetsList.add(
                          GestureDetector(
                            child: Text('${photosUrls['large'] != null ? photosUrls['large'] : ''}', style: _textStyleUrl,),
                            onTap: () async {
                              setState(() {});
                              Clipboard.setData(ClipboardData(text: '${photosUrls['large']}'));
                              _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("Copied large size photo url")));
                            }
                          )
                        );
                        if (photosUrls['large'] != null) {
                          _widgetsList.add(
                            Image.network(photosUrls['large'])
                          );
                        }

                        setState(() => _parsedWidgets = _widgetsList);                   
                      },
                    ),
                  ),

                  Container( // Parse video
                    width: 128,
                    padding: EdgeInsets.only(left: 0.0, right: 0.0, bottom: 16.0),
                    child: RaisedButton(
                      child: Text('Get video', style: _textStyleUrl,),
                      onPressed: () async {
                        List<Widget> _widgetsList = [];
                        String _videoUrl = await InstaParser.videoUrlFromPost('${_postUrlController.text}');

                        // Divider
                        _widgetsList.add(
                          Container(padding: EdgeInsets.only(top: 8.0, bottom: 8.0), 
                            child: Divider(height: 0.0, color: Colors.black)
                          )
                        );

                        // Video URL
                        _widgetsList.add(Text('Video:', style: _textStyleBold));
                        _widgetsList.add(
                          GestureDetector(
                            child: Text('$_videoUrl\n', style: _textStyleUrl,),
                            onTap: () async {
                              setState(() {});
                              Clipboard.setData(ClipboardData(text: '$_videoUrl'));
                              _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("Copied video url")));
                            }
                          )
                        );

                        setState(() => _parsedWidgets = _widgetsList);                           
                      },
                    ),
                  ),
                ],
              ),          

              Column(children: _parsedWidgets),
            ]
          ),
        ) ,
      )
    );
  }

}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  insta_html_parser: ^0.1.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:insta_html_parser/insta_html_parser.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
25
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
63
Learn more about scoring.

We analyzed this package on Oct 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/insta_html_parser.dart.

Run flutter format to format lib/insta_html_parser.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
html ^0.14.0+2 0.14.0+3
http ^0.12.0+2 0.12.0+2
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.11 1.14.12
csslib 0.16.1
http_parser 3.1.3
meta 1.1.7
path 1.6.4
pedantic 1.8.0+1
sky_engine 0.0.99
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test