Buscar pacotes, repositórios e categorias de apps

Detalhes do pacotev0.3.0

beautiful_soup_dart

Pacote nativo do Dart inspirado na biblioteca Beautiful Soup 4 do Python. Oferece formas fáceis de navegar, pesquisar e modificar a árvore HTML.

AndroidiOSWebmacOSWindowsLinux
Downloads em 30 dias
2,8 mil
Curtidas
113
Pontos Pub
160

Instalar pacote

flutter pub add beautiful_soup_dart

Visão geral do pacote

Orientação gerada a partir de informações públicas. Apenas para referência.

Uma biblioteca de análise de HTML nativa em Dart inspirada no Beautiful Soup 4 do Python. Permite navegação, pesquisa e modificação de documentos HTML de forma fácil por meio de uma API simples e intuitiva. Ideal para extração de dados de conteúdo HTML ou manipulação de estruturas DOM em aplicativos Flutter e outros aplicativos Dart. O pacote suporta todas as principais plataformas, incluindo web, móvel e desktop.

Casos de uso

  • Web scraping conteúdo HTML
  • Análise de respostas HTML dinâmicas
  • Extraindo dados estruturados de páginas da web
  • Modificando HTML antes da renderização
  • Construindo geradores de sites estáticos

Principais recursos

  • Seletores CSS e de tag intuitivos
  • Navegação fácil por relações pai/filho
  • Suporte para extração de texto e atributos
  • Métodos de busca flexíveis (find, findAll)
  • Compatibilidade multiplataforma

Indicado para

  • Desenvolvedores analisando HTML em aplicativos Flutter
  • Extração de dados de fontes da web
  • Ferramentas que exigem manipulação do DOM
  • Fluxos de trabalho de geração de site estático

Considerações

  • Não otimizado para arquivos HTML grandes
  • Limitado à análise, não renderização de HTML
  • Requer manipulação cuidadosa de entrada malformada
  • Sem suporte embutido para execução de JavaScript

README original

Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.

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.

Categorias

Dependências

Lista de dependências 1 itens

Repositório-fonte

Projetos que usam este pacote