antonio-nicolau / chaleno

A Dart package to web scraping data from websites easily and faster using less code lines.
MIT License
34 stars 12 forks source link

XML #3

Open dovahkinnn opened 3 years ago

dovahkinnn commented 3 years ago

Chaleno [ UrlException ] : XMLHttpRequest error. Error: Invalid argument (source): Must be a String or List.: null

jaisonklemer commented 3 years ago

Can you provide us with more information and how to reproduce this error?

bynicodevelop commented 2 years ago

Hi @jaisonklemer,

I have this error too in Web app.

You can find sample code :

Future<Map<String, String>> extractMeta() async {
    Completer<Map<String, String>> completer = Completer();

    Chaleno().load(src.toString()).then((value) {
      List<String> images = value!
          .getElementsByTagName("meta")!
          .where((result) => result.attr("property") == "og:image")
          .map((Result e) => e.attr("content").toString())
          .toList();

      List<String> description = value
          .getElementsByTagName("meta")!
          .where((result) => result.attr("name") == "description")
          .map((Result e) => e.attr("content").toString())
          .toList();

      return completer.complete({
        "title": value.title() ?? "",
        "description": description.isNotEmpty ? description.first : "",
        "image": images.isNotEmpty ? images.first : "",
      });
    }).catchError((error) => print(error));

    return completer.future;
  }

I hope this will help you, because your library is easy to use and this bug fix will allow me to continue developing my Flutter app for the web.

If you have any questions, I am available

bynicodevelop commented 2 years ago

It seems that this code is not working on the web :

import 'package:http/http.dart';

Response response = await Client().get(Uri.parse(src));

And generates the following error:

Error: XMLHttpRequest error.
dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 908:28                get current
packages/http/src/browser_client.dart 69:22                                       <fn>
dart-sdk/lib/async/zone.dart 1687:54                                              runUnary
dart-sdk/lib/async/future_impl.dart 160:18                                        handleValue
dart-sdk/lib/async/future_impl.dart 767:44                                        handleValueCallback
dart-sdk/lib/async/future_impl.dart 796:13                                        _propagateToListeners
dart-sdk/lib/async/future_impl.dart 593:7                                         [_complete]
dart-sdk/lib/async/stream_pipe.dart 61:11                                         _cancelAndValue
dart-sdk/lib/async/stream.dart 1232:7                                             <fn>
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 334:14  _checkAndCall
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 339:39  dcall
dart-sdk/lib/html/dart2js/html_dart2js.dart 37332:58                              <fn>
    at Object.createErrorWithStack (http://localhost:61672/dart_sdk.js:5074:12)
    at Object._rethrow (http://localhost:61672/dart_sdk.js:38925:16)
    at async._AsyncCallbackEntry.new.callback (http://localhost:61672/dart_sdk.js:38921:13)
    at Object._microtaskLoop (http://localhost:61672/dart_sdk.js:38778:13)
    at _startMicrotaskLoop (http://localhost:61672/dart_sdk.js:38784:13)
    at http://localhost:61672/dart_sdk.js:34519:9

Whatever the URL

antonio-nicolau commented 2 years ago

Hey @bynicodevelop thanks for the aditional information and sorry for the delay. it seems to be a error related the flutter-web more specifically with the CORS

You should add CORS support to your API. it just happen on the web

There's nothing we can do on the Flutter side. This is a fundamental limitation on the Web. When sending HTTP requests (XHR) the server you are communicating with needs to allow it via a CORS handshake