スクレイピングアプリ作成開始[作業メモ]

今度はスクレイピングを学びたくなってきたので、それを使ったアプリを作成していく。

今日はどうすればいいのかまったくわからないのでその調査

前調査

とりあえず、flutterでスクレイピングをしている日本語記事を探す。
https://qiita.com/toda-axiaworks/items/dd05264d5a7953316494
https://zenn.dev/7oh/articles/fe9fa855859011

どうやら、universal_htmlを使うのがいいらしい。
https://pub.dev/packages/universal_html

ただ、日本語記事で使っていた以下のパッケージがない。なんでだw

import 'package:universal_html/driver.dart';

わからないのでとりあえずuniversal_htmlの使い方をサイトを読みながら学んでいくことにした。
Read me のGetting stratに「Scrapin a website」というそれっぽいものがあったので動かしてみる。
https://pub.dev/documentation/universal_html/latest/universal_html.controller/WindowController-class.html

とりあえず動いて、「1」が出力された。どういうことだ?
おそらくwebサイトからなんらかのスクレピングが行われたみたいだけど、HTMLもCSSの知識もないので良くわからない。

Future<void> main() async {

 final controller = WindowController();
 await controller.openHttp(
   method: 'GET',
   uri: Uri.parse('https://news.ycombinator.com/'),
 );
 final document = controller.window!.document;
 final topStorytitle = document.querySelectorAll(".athing > .title").first.text;
 print(topStorytitle);
 runApp(const MyApp());

}

スクレイピングしてるっぽいところが

final topStorytitle = document.querySelectorAll(".athing > .title").first.text;

ここっぽいので、.querySelectorAllについて調べていく。
https://api.flutter.dev/flutter/dart-html/querySelectorAll.html

わからんので明日もCSSとかHTML周りの勉強を少しだけしようと思う。


この記事が気に入ったらサポートをしてみませんか?