beautifulsoup 0.0.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 69

"Provide idiomatic ways of navigating, searching, and modifying the parse tree. It commonly saves programmers hours or days of work"

Usage #

A simple usage example:

import 'package:beautifulsoup/beautifulsoup.dart';

main() {
  String document = """
  <html><head><title>The Dormouse's story</title></head>
  <body>
  <p class="title"><b>The Dormouse's story</b></p>

  <p class="story">Once upon a time there were three little sisters; and their names were
  <a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>,
  <a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
  <a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;
  and they lived at the bottom of a well.</p>

  <p class="story">...</p>
  """;
  
  var soup = Beautifulsoup(document);
  
  print(soup("title").outerHtml); //soup.title
  print(soup("title").localName); //soup.title.name
  print(soup("title").text); //soup.title.string
  print(soup("title").parent.localName); //soup.title.parent.name
  print(soup("p").outerHtml); //soup.title.parent.name
  print(soup("p").attributes["class"]); //soup.p['class']
  print(soup("a").outerHtml); //soup.a
  print(soup.get_text()); //soup.get_text()
  print(soup.find_all("a").map((e)=> (e.outerHtml)).toList());
}

Modifying text via class name

  String document = """
   <p id="RipVanWinkle">
    RipVanWinkle paragraph.
  </p>
    """;
    
  var soup = Beautifulsoup(document);
  soup.find(id:"#RipVanWinkle").text = "Wake up, sleepy head!";
  print(soup.print());

Modify text by tag

  String document = """
  <a href="http://example.com/">I linked to <i>example.com</i></a>
  """;
    
  var soup = Beautifulsoup(document);
  soup("a").text ="New link text";
  print(soup.print());

Find all links in a html document

String document = """
    <html>
    <head>
      <title>
      The Dormouse's story
      </title>
    </head>
    <body>
      <p class="title">
      <b>
        The Dormouse's story
      </b>
      </p>
      <p class="story">
      Once upon a time there were three little sisters; and their names were
      <a class="sister" href="http://example.com/elsie" id="link1">
        Elsie
      </a>
      ,
      <a class="sister" href="http://example.com/lacie" id="link2">
        Lacie
      </a>
      and
      <a class="sister" href="http://example.com/tillie" id="link2">
        Tillie
      </a>
      ; and they lived at the bottom of a well.
      </p>
      <p class="story">
      ...
      </p>
    </body>
    </html>
    """;
    
    var soup = Beautifulsoup(document);
    var hyperlinks = soup.find_all("a").map((e)=> print(soup.attr(e,"href"))).toList();
    

Features and bugs #

Please file feature requests and bugs at the issue tracker.

1.0.0 #

  • Initial version, created by Stagehand

example/beautifulsoup_example.dart

import 'package:beautifulsoup/beautifulsoup.dart';

main() {
  String document = """
  <html><head><title>The Dormouse's story</title></head>
  <body>
  <p class="title"><b>The Dormouse's story</b></p>

  <p class="story">Once upon a time there were three little sisters; and their names were
  <a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>,
  <a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
  <a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;
  and they lived at the bottom of a well.</p>

  <p class="story">...</p>
  """;
  
  var soup = Beautifulsoup(document);
  
  print(soup("title").outerHtml); //soup.title
  print(soup("title").localName); //soup.title.name
  print(soup("title").text); //soup.title.string
  print(soup("title").parent.localName); //soup.title.parent.name
  print(soup("p").outerHtml); //soup.title.parent.name
  print(soup("p").attributes["class"]); //soup.p['class']
  print(soup("a").outerHtml); //soup.a
  print(soup.get_text()); //soup.get_text()
  print(soup.find_all("a").map((e)=> (e.outerHtml)).toList());
}

Use this package as a library

1. Depend on it

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


dependencies:
  beautifulsoup: ^0.0.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or 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:beautifulsoup/beautifulsoup.dart';
  
Version Uploaded Documentation Archive
0.0.1 Feb 16, 2019 Go to the documentation of beautifulsoup 0.0.1 Download beautifulsoup 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
51
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
69
Overall:
Weighted score of the above. [more]
69
Learn more about scoring.

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

  • Dart: 2.3.2
  • pana: 0.12.18

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:beautifulsoup/beautifulsoup.dart.

Health issues and suggestions

Document public APIs. (-1 points)

13 out of 13 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/beautifulsoup.dart. (-0.50 points)

Analysis of lib/beautifulsoup.dart reported 1 hint:

line 1 col 8: Unused import: 'dart:collection'.

Maintenance issues and suggestions

Support latest dependencies. (-15 points)

The version constraint in pubspec.yaml does not support the latest published versions for 2 dependencies (1 direct: html).

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

The package description is too short. (-6 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
html ^0.13.3+3 0.13.4+2 0.14.0+2
Transitive dependencies
charcode 1.1.2
csslib 0.15.0 0.16.0
path 1.6.2
source_span 1.5.5
term_glyph 1.1.0
utf 0.9.0+5
Dev dependencies
test ^1.0.0