패키지, 저장소 및 앱 카테고리 검색

패키지 상세v0.3.0

beautiful_soup_dart

Python의 Beautiful Soup 4 라이브러리에서 영감을 받은 Dart 네이티브 패키지입니다. HTML 트리를 탐색하고 검색하며 수정하는 쉬운 방법을 제공합니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
2.8천
좋아요
113
Pub 점수
160

패키지 설치

flutter pub add beautiful_soup_dart

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

파이썬의 Beautiful Soup 4에 영감을 받은 원격 Dart HTML 파싱 라이브러리입니다. 간단하고 직관적인 API를 통해 HTML 문서 탐색, 검색 및 수정을 쉽게 가능하게 합니다. Flutter 및 기타 Dart 애플리케이션에서 HTML 콘텐츠에서 데이터를 추출하거나 DOM 구조를 조작하는 데 이상적입니다. 이 패키지는 웹, 모바일, 데스크톱을 포함한 모든 주요 플랫폼을 지원합니다.

사용 사례

  • 웹 스크래핑 HTML 콘텐츠
  • 동적 HTML 응답 분석
  • 웹 페이지에서 구조화된 데이터 추출하기
  • 렌더링 전에 HTML 수정하기
  • 정적 사이트 생성기 만들기

주요 기능

  • 직관적인 CSS 및 태그 선택기
  • 부모/자식 관계를 통한 간편한 탐색
  • 텍스트 및 속성 추출 지원
  • 유연한 검색 방법(find, findAll)
  • 크로스 플랫폼 호환성

적합한 대상

  • Flutter 앱에서 HTML을 파싱하는 개발자
  • 웹 소스에서 데이터 추출
  • DOM 조작이 필요한 도구
  • 정적 사이트 생성 워크플로

고려 사항

  • 대규모 HTML 파일에 최적화되지 않음
  • 구문 분석에만 제한됨, HTML 렌더링은 불가능
  • 잘못된 입력을 신중하게 처리해야 합니다
  • 자바스크립트 실행을 위한 내장 지원 없음

원본 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 개

소스 저장소

이 패키지를 사용하는 프로젝트