環境
■flutter doctor
[✓] Flutter (Channel beta, 2.2.0-10.2.pre, on macOS 11.3.1 20E241 darwin-x64, locale ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.56.2)
[✓] Connected device (2 available)
■dart –version
Dart SDK version: 2.13.0-211.13.beta (beta) (Mon Apr 26 14:25:18 2021 +0200) on "macos_x64"
■Google Chrome
インストールしていることが前提です。
Google Chrome は最新版です
バージョン: 90.0.4430.212(Official Build) (x86_64)
昔pythonでスクレイピングした際、headless専用のGoogle Chromeをインストールした記憶ですが、普通にChromeをインストールすればheadlessとして使用できるようです。
動かしてみる
VSCodeから動かしてみます。
このページからリポジトリをダウンロード(クローン)する。
VSCodeで開き、依存するパッケージを取得する。
launch.jsonに実行するプログラムを設定する。
launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "puppeteer-dart-master",
"request": "launch",
"type": "dart",
"program": "example/screenshot_page.dart",
}
]
}
プログラムを実行する(F5)。
そうするとフォルダに「_github.png」というファイルができます。

「https://dart.dev」というurlのスクリーンショットが取得できています。

コメント