搜尋套件、儲存庫與 APP 分類

套件詳情v0.1.4

web_scraper

一個簡單的網頁爬蟲,用於抓取HTML標籤及其屬性,並轉換為Dart和Flutter中的清單和映射。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
1080
喜歡數
295
Pub 分數
140

安裝套件

flutter pub add web_scraper

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個輕量級的 Flutter/Dart 套件,用於透過抓取標籤及其屬性來提取 HTML 內容,並轉換為結構化的 Dart 清單與映射。非常適合解析靜態網頁或從 HTML 源取得資料,而無需進行完整的 DOM 操作。它支援多種平台,包括行動裝置、Web 與桌面端,使其成為需要從 HTML 回應中提取結構化資料的跨平台應用程式的多功能選擇。

適用情境

  • 從靜態網頁中提取數據
  • 解析 HTML 表格和列表
  • 從網頁內容中抓取元數據
  • 從HTML來源填入本地資料
  • 構建簡單的網路爬蟲

主要特色

  • 用於HTML標籤提取的簡單API
  • 支援屬性和文字內容的檢索
  • 將抓取的資料轉換為 Dart 列表和映射
  • 跨平台相容性
  • 輕量且易於整合

適合對象

  • 開發數據獲取應用的開發者
  • 需要HTML解析但不使用重型框架的項目
  • 原型設計網路爬蟲功能
  • 需要最少伺服器端處理的應用程式

使用建議

  • 不適用於動態 JavaScript 渲染的內容
  • 需要有效的HTML輸入
  • 可能無法優雅地處理錯誤格式的HTML
  • 僅限靜態頁面抓取
  • 依賴外部HTML來源的可靠性

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Pub

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);
    }

Checkout web_scraper_test.dart file to have closer look on all functionalities.

Methods

Method Description Arguments Return Type
loadWebPage 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.

Built by developers, for Developers.

Backed up permanently on-chain using Sadaiv CI.

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。