태그와 그 속성을 스크래핑하여 HTML 콘텐츠를 추출하고, 이를 구조화된 Dart 리스트와 맵으로 변환하는 가벼운 Flutter/Dart 패키지입니다. 완전한 DOM 조작 없이 정적 웹 페이지를 파싱하거나 HTML 소스에서 데이터를 가져오는 데 이상적입니다. 모바일, 웹, 데스크톱을 포함한 여러 플랫폼을 지원하여 HTML 응답에서 구조화된 데이터를 추출해야 하는 크로스플랫폼 애플리케이션에 매우 유연하게 활용할 수 있습니다.
사용 사례
정적 웹 페이지에서 데이터 추출하기
HTML 테이블과 목록 파싱
웹 콘텐츠에서 메타데이터 스크래핑하기
HTML 소스에서 로컬 데이터 채우기
간단한 웹 크롤러 만들기
주요 기능
HTML 태그 추출을 위한 간단한 API
속성 및 텍스트 콘텐츠 검색을 지원합니다
스크래핑된 데이터를 Dart 리스트와 맵으로 변환합니다
크로스 플랫폼 호환성
경량이며 통합이 쉬움
적합한 대상
데이터 가져오기 앱을 개발하는 개발자
무거운 프레임워크 없이 HTML 파싱이 필요한 프로젝트
웹 스크래핑 기능 프로토타이핑
최소한의 서버 측 처리를 필요로 하는 앱
고려 사항
동적 자바스크립트 렌더링 콘텐츠에 적합하지 않습니다
유효한 HTML 입력이 필요합니다
잘못된 HTML을 우아하게 처리하지 못할 수 있습니다
정적 페이지 스크래핑에 제한됨
외부 HTML 소스의 신뢰성에 의존
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
A Simple Web Scraper for Dart & Flutter
A very basic web scraper implementation to scrap html elements from a web page.
Pull requests are most welcome.
Getting Started
In your pubspec.yaml root add:
dependencies:web_scraper:
then,
import'package:web_scraper/web_scraper.dart';
Note that as of version 0.0.6, the project supports not only Flutter projects, but also Dart projects.
Implementation
final webScraper = WebScraper('https://webscraper.io');
if (await webScraper.loadWebPage('/test-sites/e-commerce/allinone')) {
List<Map<String, dynamic>> elements = webScraper.getElement('div.thumbnail > div.caption', ['h4']);
print(elements);
}
Loads the webpage into response object and then parse it into the document object
String route
Future <bool>
loadFromURL
Loads the webpage from provided URL into response object and then parse it into the document object
String page
Future <bool>
loadFromString
Loads the webpage from a String (usually stored by the getPageContent method) into response object and then parse it into the document object. This operation is completely synchronous and exists as a helper method to perform compute() flutter operations and avoid jank
String responseBodyAsString
Future <bool>
getPageContent
Returns webpage's html in string format
Void
String body
getElement
Returns List of elements found at specified address
String address, List <String> attributes
List <Map<String, dynamic>>
getElementTitle
Returns List of element titles found at specified address
String address
List <String>
getElementAttribute
Returns List of elements single attribute found at specified address (if you wish to get multiple attributes at once, please use getElement instead)
String address, List <String> attributes
List <String>
getAllScripts
Returns the list of all data enclosed in script tags of the document
Void
List <String>
getScriptVariables
Returns Map between given variable names and list of their occurence in the script tags
List <String> variableNames
Map <String, dynamic>
Contributing
Please branch from develop to implement bug fix/new feature.
Ensure that code is formatted according to base dart rules & using the latest stable version of dart.
Open a PR with develop as the PR target with a clear description.