Run Crawlers on Your Phone! A First Look at a Flutter Crawler Framework~
Recently I needed a lot of data to train models for my graduation project. Many sites also have anti-crawling mechanisms, so I have to crawl for a while then pause, which makes it extremely slow. Running a crawler on my computer 24 hours a day would use too much electricity, so I thought of using my phone~ Then I thought of Flutter—old Android and Apple phones can all be put to use for data collection. ok, then I started building. After a day of tinkering I put together a rough framework. Finally I can conveniently add crawler tasks. It integrates basic features like config, logging, and data persistence, then wraps network requests and webpage parsing. It works reasonably well. Except, as everyone knows, dart
目录6 个章节
Recently I needed a lot of data to train models for my graduation project. Many sites also have anti-crawling mechanisms, so I have to crawl for a while then pause, which makes it extremely slow. Running a crawler on my computer 24 hours a day would use too much electricity, so I thought of using my phone~
Then I thought of Flutter—old Android and Apple phones can all be put to use for data collection.
ok, then I started building. After a day of tinkering I put together a rough framework. Finally I can conveniently add crawler tasks. It integrates basic features like config, logging, and data persistence, then wraps network requests and webpage parsing. It works reasonably well.
Except, as everyone knows, Dart is a single-threaded language. Although it provides an isolate mechanism, it can't share memory, so using it feels like having your hands tied. And Flutter even disabled reflection! The Google team is really something. After an afternoon of struggling I got so pissed off by this piece of junk that I simply abandoned the project.
If I want to implement a multi-threaded crawler, it looks like I'd have to write some native code anyway, in which case I might as well go fully native...
(ps: Why use this junk Flutter for crawling when perfectly good Android native is sitting there?? I must have gone nuts. So pissed off.)

App Screenshots

System Architecture
Drew a few diagrams

The SpiderTask base class. All crawler classes derive from this class. SpiderTask itself maintains a TaskConfig task configuration object and a logging object. As shown below:

As for data persistence, I used another class with the singleton pattern, initialized when the app starts.

Workflow
- Register crawler tasks in the task list on the home page
- After launching the app, manage each crawler task on the main page
- Select a task and start it
- Entering the detail page automatically binds to the crawler task's logging object so you can see log output
A Simple Example
Here's a simple example. When run, it crawls news from the CN Radio website.
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_spider_fx/framework/index.dart';
class CNRadioNewsSpider extends SpiderTask {
var url = 'http://news.cnr.cn/';
CNRadioNewsSpider(BuildContext context) : super(context, 'CNRadioNewsSpider');
@override
start() async {
super.start();
var dom = await CatHttp.getDocument(url, encoding: 'gb2312');
var links = dom.querySelectorAll('.contentPanel .lh30 a');
links.forEach((link) {
logging.debug(link.attributes['href']);
logging.info(link.text);
});
}
}
Framework Code
For more details, you can check out the project code on GitHub~
Project URL: https://github.com/Deali-Axy/flutter_spider_fx
One last thing: junk Flutter. Don't blindly worship Google's tech. This thing is still a trap right now. Fine for writing a simple GUI to do CRUD, but don't even think about advanced stuff.

Welcome to Chat
For questions, please leave a message on the WeChat official account backend. I'll reply to every message~
- WeChat official account: 画星星高手
- Coding livestream: https://live.bilibili.com/11883038
- Zhihu: https://www.zhihu.com/people/dealiaxy
- Column: https://zhuanlan.zhihu.com/deali
- Jianshu: https://www.jianshu.com/u/965b95853b9f
_EOF_
Run Crawlers on Your Phone! A First Look at a Flutter Crawler Framework~
- 本文作者:
- 程序设计实验室
- 版权声明:
- 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
相关文章
初见Flutter!框架简单介绍以及构建可发布的签名Apk包
哈喽!好久不见,算起来我已经一个多月没更新博客了,近期刚刚完成了一个项目,正好抽出时间整理一下学到的东西并且写写博客。 关于flutter 开始使用flutter还是春节后的事情,其实之前很早就想学一下flutter了,毕竟谷歌出的技术总是不会太差的,无奈一直没有时间和做app的需求,这次接触了flutter之后仿佛发现了新大陆,原来开发app还能这么方便,真的颠覆了我原来的认知啊,热更新也太好用
2021-12-18 · Flutter · 约 1 分钟
Flutter编译失败:java-nio-file-NoSuchFileException--build-app-intermediates
FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:mergeExtDexDebug'. A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$Acti
2021-12-18 · Flutter · 约 1 分钟
Windows上怎么配置flutter开发环境?这篇文章手把手教你
前言 在Windows上做开发,一个字:坑。 但是有时候外出只能带着笔记本,Linux在一些笔记本上不太兼容,驱动支持不完美,而且电源管理不够好,所以无奈的情况下只能用Windows暂时顶一下,就像现在我要在Windows上搭建Flutter的开发环境一样,太坑了。 进入正题 先安装Android SDK 首先,你要有一种可以下载到Android SDK的方式,可以是梯子,或者是国内镜像,具体我就
2023-03-05 · Flutter · 约 1 分钟
Flutter移动应用快速构建实践——状态管理、国际化、数据持久化、性能优化(二)
继续上一篇:极简诗词开发背后:Flutter移动应用快速构建实践——状态管理、国际化、数据持久化、性能优化(一) 前文中说到了项目结构、状态管理和国际化的方案,本文继续聊聊数据持久化和粗略的性能优化。 数据持久化 目前的话,flutter用的比较多比较成熟的数据持久化就是shared_preferences和SQFLite,一个是ini配置文件,一个是SQLite数据库,小应用我比较倾向只用前者,
2021-12-18 · Flutter · 约 1 分钟
讨论
共 0 条加载评论中…