dart_spider 0.0.4 copy "dart_spider: ^0.0.4" to clipboard
dart_spider: ^0.0.4 copied to clipboard

discontinued
outdated

Dart Spider is a simple package to extract information from URLs.

example/example.dart

import 'package:dart_spider/dart_spider.dart';
import 'dart:convert';
import 'dart:io'; //Just for input from console

void main() async {
  //Config
  Map<String, Config> masterConfig = {
    "example.com": Config(
      parsers: {
        "homepage": [
          Parser(
            id: "title",
            parent: ["_root"],
            type: ParserType.text,
            selector: "h1",
          ),
          Parser(
            id: "description",
            parent: ["_root"],
            type: ParserType.text,
            selector: "p",
            optional: Optional(
              nth: 1,
            ),
          ),
          Parser(
            id: "link",
            parent: ["_root"],
            type: ParserType.url,
            selector: "a",
          ),
        ],
      },
      targets: [
        Target(name: "homepage", where: ["/"]),
      ],
    ),
  };

  //URL input from console
  stdout.write('URL: ');
  String? url = stdin.readLineSync();

  //Scrape from URL
  var res = await Spider.scrapeFromUrl(
    masterConfig,
    url,
    extract: Extract.product,
  );
  //Check if it's successful
  if (res is SpiderError) {
    print(res.error);
  } else {
    //Success
    print(jsonEncode(res));
  }
}
4
likes
0
points
16
downloads

Publisher

verified publisherpricehistoryapp.com

Weekly Downloads

Dart Spider is a simple package to extract information from URLs.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

html, http

More

Packages that depend on dart_spider