パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v0.3.0

beautiful_soup_dart

PythonのBeautiful Soup 4ライブラリを参考にしたDartネイティブパッケージ。HTMLツリーのナビゲーション、検索、編集を簡単に行う方法を提供します。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
2950
いいね数
113
Pub ポイント
160

パッケージをインストール

flutter pub add beautiful_soup_dart

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

PythonのBeautiful Soup 4にインスパイアされたネイティブDartのHTMLパーサーライブラリです。シンプルで直感的なAPIを通じて、HTMLドキュメントのナビゲーション、検索、および修正を容易に行えます。Flutterや他のDartアプリケーションでHTMLコンテンツからデータを抽出したり、DOM構造を操作するのに最適です。このパッケージはWeb、モバイル、デスクトップを含むすべての主要プラットフォームをサポートしています。

用途

  • Web スクレイピング HTML コンテンツ
  • 動的HTML応答の解析
  • ウェブページから構造化データを抽出する
  • レンダリング前に HTML を変更する
  • 静的サイトジェネレーターの構築

主な機能

  • 直感的な CSS およびタグセレクター
  • 親/子関係を介した簡単なナビゲーション
  • テキストおよび属性の抽出に対応
  • 柔軟な検索メソッド(find、findAll)
  • クロスプラットフォーム互換性

適している対象

  • FlutterアプリでHTMLをパースする開発者
  • Webソースからのデータ抽出
  • DOM操作を必要とするツール
  • スタティックサイト生成ワークフロー

注意事項

  • 大規模なHTMLファイルには最適化されていません
  • パースに限定され、HTMLのレンダリングは行わない
  • 不正な入力を慎重に扱う必要があります
  • JavaScript 実行の組み込みサポートなし

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

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.

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

このパッケージを使用しているプロジェクト