metadata_fetch 0.3.3

Dart native js
Flutter Android iOS web

A dart library for extracting metadata on web pages such as OpenGraph, Meta, Twitter Cards, and Structured Data (Json-LD)

Metadata Fetch #

A dart library for extracting metadata in web pages. Supports OpenGraph, Meta, Twitter Cards, and Structured Data (Json-LD)

Usage #

Extract Metadata for a given URL #

import 'package:metadata_fetch/metadata_fetch.dart';

main() async {
  var data = extract("https://flutter.dev/"); // Use the extract() function to fetch data from the url

  print(data.title) // Flutter - Beautiful native apps in record time

  print(data.description) // Flutter is Google's UI toolkit for crafting beautiful...

  print(data.image) // https://flutter.dev/images/flutter-logo-sharing.png

  var dataAsMap = data.toMap();

}

Parsing Manually #

Get aggregated Metadata from a document

This method prioritizes Open Graph data, followed by Twitter Card, JSON-LD and finally falls back too HTML metadata.

import 'package:metadata_fetch/metadata_fetch.dart';
import 'package:http/http.dart' as http;

void main () async {

  // Makes a call
  var response = await http.get('https://flutter.dev');

  // Covert Response to a Document. The utility function `responseToDocument` is provided or you can use own decoder/parser.
  var document = responseToDocument(response);


  // get metadata
  var data = MetadataParser.parse(document);
  print(data);


}

Get Open Graph Metadata

import 'package:metadata_fetch/metadata_fetch.dart';
import 'package:http/http.dart' as http;

void main () async {

  // Makes a call
  var response = await http.get('https://flutter.dev');

  // Covert Response to a Document. The utility function `responseToDocument` is provided or you can use own decoder/parser.
  var document = responseToDocument(response);


  // get metadata
  var data = MetadataParser.OpenGraph(document);
  print(data);


}

Get Html Metadata

import 'package:metadata_fetch/metadata_fetch.dart';
import 'package:http/http.dart' as http;

void main () async {

  // Makes a call
  var response = await http.get('https://flutter.dev');

  // Covert Response to a Document. The utility function `responseToDocument` is provided or you can use own decoder/parser.
  var document = responseToDocument(response);


  // get metadata
  var data = MetadataParser.HtmlMeta(document);
  print(data);
}

Get Structured Data (Json+LD)

import 'package:metadata_fetch/metadata_fetch.dart';
import 'package:http/http.dart' as http;

void main () async {

  // Makes a call
  var response = await http.get('https://flutter.dev');

  // Covert Response to a Document. The utility function `responseToDocument` is provided or you can use own decoder/parser.
  var document = responseToDocument(response);


  // Just Json-ld schema
  var data = MetadataParser.JsonLdSchema(document);
  print(data);
}

Get Twitter Cards Metadata

import 'package:metadata_fetch/metadata_fetch.dart';
import 'package:http/http.dart' as http;

void main () async {

  // Makes a call
  var response = await http.get('https://www.epicurious.com/expert-advice/best-soy-sauce-chefs-pick-article');

  // Covert Response to a Document. The utility function `responseToDocument` is provided or you can use own decoder/parser.
  var document = responseToDocument(response);


  // Get Twitter Card metadata
  var data = MetadataParser.TwitterCard(document);
  print(data);
}

Credit #

This library is inspired by open_graph_parser. However this one tries to be more general.

Roadmap #

  • Weighted or Preferred Metadata. Can assign custom weights for each parser to provide a fallback priority sytem
  • Improve Documentation

Questions, Bugs, and Feature Requests #

Please forward all queries about this project to the issue tracker.

27
likes
80
pub points
86%
popularity

A dart library for extracting metadata on web pages such as OpenGraph, Meta, Twitter Cards, and Structured Data (Json-LD)

Repository (GitHub)
View/report issues

Uploader

lising.jg@gmail.com

License

BSD (LICENSE)

Dependencies

html, http, string_validator

More

Packages that depend on metadata_fetch