mobile-use数据抓取实战:从Gmail提取未读邮件到JSON格式的完整教程
mobile-use数据抓取实战:从Gmail提取未读邮件到JSON格式的完整教程
【免费下载链接】mobile-useAI agents can now use real Android and iOS apps, just like a human.项目地址: https://gitcode.com/gh_mirrors/mobil/mobile-use
mobile-use是一款强大的AI代理工具,能够像人类一样操作真实的Android和iOS应用程序,实现自动化数据抓取任务。本教程将详细介绍如何使用mobile-use从Gmail提取未读邮件并保存为JSON格式,帮助你轻松实现邮件数据的自动化处理。
📋 准备工作
在开始之前,请确保你已经完成以下准备工作:
- 克隆项目仓库:
git clone https://gitcode.com/gh_mirrors/mobil/mobile-use - 安装必要的依赖(具体步骤请参考项目文档)
- 配置API密钥:访问平台获取API密钥,并设置
MINITAP_API_KEY和MINITAP_BASE_URL环境变量
🤖 了解mobile-use的工作流程
mobile-use通过AI代理模拟人类操作移动应用,其核心工作流程如下:
- 接收任务指令
- 分析应用界面
- 执行操作步骤
- 提取所需数据
- 按照指定格式输出结果
mobile-use AI代理操作演示:通过自然语言指令完成应用操作
🔍 提取Gmail未读邮件的实现方法
mobile-use提供了简洁的API来创建和执行任务。下面是从Gmail提取未读邮件并保存为JSON格式的关键步骤:
设置任务目标和输出格式
在代码中,我们需要明确指定任务目标和期望的输出格式。例如:
ManualTaskConfig( goal="Find the first 3 unread emails in Gmail", output_description="A JSON array with sender and subject for each email", )这段代码定义了两个关键参数:
goal: 告诉AI代理需要完成的任务 - "查找Gmail中的前3封未读邮件"output_description: 指定输出格式 - "包含每封邮件发件人和主题的JSON数组"
锁定目标应用
为了确保任务在Gmail应用中执行,我们需要锁定Gmail应用:
locked_app_package="com.google.android.gm"这个参数确保AI代理会自动启动并锁定Gmail应用,专注于完成指定任务。
🚀 完整实现步骤
以下是使用mobile-use从Gmail提取未读邮件到JSON的完整步骤:
1. 导入必要的模块
import asyncio from minitap.mobile_use.sdk import Agent from minitap.mobile_use.sdk.types import ManualTaskConfig, PlatformTaskRequest2. 创建主函数
async def main() -> None: agent = Agent() await agent.init() # 执行邮件提取任务 result = await agent.run_task( request=PlatformTaskRequest( task=ManualTaskConfig( goal="Find the first 3 unread emails in Gmail", output_description="A JSON array with sender and subject for each email", ), ), locked_app_package="com.google.android.gm", ) print("提取结果:", result) await agent.clean() if __name__ == "__main__": asyncio.run(main())3. 运行脚本
执行以下命令运行脚本:
python minitap/mobile_use/sdk/examples/platform_manual_task_example.py💡 预期输出结果
成功执行后,你将得到类似以下格式的JSON结果:
[ {"sender": "example1@domain.com", "subject": "会议通知:项目进度讨论"}, {"sender": "example2@domain.com", "subject": "您的订单已发货"}, {"sender": "example3@domain.com", "subject": "新邮件通知"} ]📝 自定义任务扩展
你可以根据需要修改任务目标和输出格式,例如:
- 提取更多邮件信息:发件人、主题、日期、摘要
- 筛选特定发件人的邮件
- 设置邮件数量限制
修改goal和output_description参数即可实现自定义需求,例如:
goal="Find all unread emails from work@company.com in the last 7 days", output_description="A JSON array with sender, subject, date and snippet for each email"📚 更多资源
- 项目示例代码:minitap/mobile_use/sdk/examples/
- 任务构建器:minitap/mobile_use/sdk/builders/task_request_builder.py
- 配置指南:skills/mobile-use-setup/
通过本教程,你已经掌握了使用mobile-use从Gmail提取未读邮件并保存为JSON格式的方法。mobile-use的强大之处在于它能够模拟人类操作各种移动应用,为数据抓取和自动化任务提供了无限可能。开始探索吧!
【免费下载链接】mobile-useAI agents can now use real Android and iOS apps, just like a human.项目地址: https://gitcode.com/gh_mirrors/mobil/mobile-use
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
