Pakete, Repositories und App-Kategorien suchen

Paketdetailsv0.3.0

beautiful_soup_dart

Dart-native Paket, inspiriert durch die Beautiful Soup 4 Python-Bibliothek. Bietet einfache Möglichkeiten zum Navigieren, Suchen und Bearbeiten des HTML-Baums.

AndroidiOSWebmacOSWindowsLinux
30-Tage-Downloads
2800
Likes
113
Pub-Punkte
160

Paket installieren

flutter pub add beautiful_soup_dart

Paketübersicht

Aus öffentlichen Paketdaten erstellte Orientierung.

Eine Dart-native HTML-Parsing-Bibliothek, die von Python's Beautiful Soup 4 inspiriert ist. Sie ermöglicht eine problemlose Navigation, Suche und Modifikation von HTML-Dokumenten über eine einfache und intuitive API. Ideal zum Extrahieren von Daten aus HTML-Inhalten oder zum Manipulieren von DOM-Strukturen in Flutter und anderen Dart-Anwendungen. Das Paket unterstützt alle wichtigen Plattformen, einschließlich Web, Mobilgeräte und Desktop.

Anwendungsfälle

  • Web Scraping HTML-Inhalt
  • Analyse dynamischer HTML-Antworten
  • Strukturierte Daten aus Webseiten extrahieren
  • HTML vor der Darstellung ändern
  • Statische Site-Generatoren erstellen

Hauptmerkmale

  • Intuitive CSS- und Tag-Auswahl
  • Einfache Navigation durch Eltern-/Kinderbeziehungen
  • Unterstützung für Text- und Attributextraktion
  • Flexible Suchmethoden (find, findAll)
  • Plattformübergreifende Kompatibilität

Geeignet für

  • Entwickler, die HTML in Flutter-Apps parsen
  • Datenextraktion aus Webquellen
  • Werkzeuge, die DOM-Manipulation erfordern
  • Workflows zur statischen Site-Generierung

Hinweise

  • Nicht für große HTML-Dateien optimiert
  • Beschränkt auf das Parsen, nicht auf das Rendern von HTML
  • Erfordert sorgfältige Behandlung fehlerhafter Eingaben
  • Keine integrierte Unterstützung für die Ausführung von JavaScript

Original-README

Originaler README-Schnappschuss aus dem verknüpften Quell-Repository. Aktuelle Inhalte finden Sie im Repository.

Beautiful Soup Dart

pub package tests codecov

Dart native package inspired by Beautiful Soup 4 Python library. Provides easy ways of navigating, searching, and modifying the HTML tree.

Usage

A simple usage example:

import 'package:beautiful_soup_dart/beautiful_soup.dart';

/// 1. parse a document String
BeautifulSoup bs = BeautifulSoup(html_doc_string);
// use BeautifulSoup.fragment(html_doc_string) if you parse a part of html

/// 2. navigate quickly to any element
bs.body!.a!; // navigate quickly with tags, use outerHtml or toString to get outer html
bs.find('p', class_: 'story'); // finds first element with html tag "p" and which has "class" attribute with value "story"
bs.findAll('a', attrs: {'class': true}); // finds all elements with html tag "a" and which have defined "class" attribute with whatever value
bs.find('', selector: '#link1'); // find with custom CSS selector (other parameters are ignored)
bs.find('*', id: 'link1'); // any element with id "link1"
bs.find('*', regex: r'^b'); // find any element which tag starts with "b", for example: body, b, ...
bs.find('p', string: r'^Article #\d*'); // find "p" element which text starts with "Article #[number]"
bs.find('a', attrs: {'href': 'http://example.com/elsie'}); // finds by "href" attribute

/// 3. perform any other actions for the navigated element
Bs4Element bs4 = bs.body!.p!; // navigate quickly with tags
bs4.name; // get tag name
bs4.string; // get text
bs4.toString(); // get String representation of this element, same as outerHtml
bs4.innerHtml; // get html elements inside the element
bs4.className; // get class attribute value
bs4['class']; // get class attribute value
bs4['class'] = 'board'; // change class attribute value to 'board'
bs4.children; // get all element's children elements
bs4.replaceWith(otherBs4Element); // replace with other element
... and many more

Check test folder for more examples.

Table of Contents

The unlinked titles are not yet implemented.

Other methods from the Element from html package can be accessed via bs4element.element.

Features and bugs

Please file feature requests and bugs at the issue tracker or feel free to raise a PR.

Kategorien

Abhängigkeiten

Abhängigkeiten 1 Einträge

Quell-Repository

Projekte, die dieses Paket verwenden