2025最新GHunt进阶技巧:突破API限制,实现批量数据采集自动化
【免费下载链接】GHunt 🕵️♂️ Offensive Google framework. 项目地址: https://gitcode.com/GitHub_Trending/gh/GHunt
你是否还在为GHunt单次请求限制而烦恼?是否希望实现Google账户相关信息的批量采集与分析?本文将系统讲解三大进阶技巧,帮助你突破API调用瓶颈,构建自动化数据采集流程,从普通用户升级为高级OSINT(开源情报)分析师。读完本文你将掌握:并发请求控制方案、Cookie池构建技巧、以及完整的批量采集脚本开发。
关于GHunt
GHunt(v2)是一个针对Google相关场景的框架,主要用于OSINT(开源情报)调查,其核心特性包括CLI使用和模块、Python库使用、完全异步、JSON导出以及便于登录的浏览器扩展。
官方文档:README.md
批量采集的核心挑战
Google的API限制主要体现在两个方面:请求频率限制和单次查询数据量限制。普通用户直接循环调用API会面临429 Too Many Requests错误,而通过浏览器手动查询更是效率低下。GHunt作为专业的Google框架,提供了底层API封装,但默认配置下仍需优化才能满足批量采集需求。
技巧一:异步并发请求控制
GHunt原生支持异步编程,通过合理配置并发数可以显著提高采集效率。核心模块位于ghunt/helpers/utils.py,其中的get_httpx_client()函数返回一个预配置的异步客户端。
# 优化后的异步客户端配置
def get_httpx_client() -> httpx.AsyncClient:
"""返回优化后的异步客户端,支持并发控制"""
limits = httpx.Limits(max_connections=10, max_keepalive_connections=5)
return AsyncClient(http2=True, timeout=15, limits=limits)
通过调整max_connections参数控制并发数,建议值为5-10。结合asyncio.gather实现批量任务调度:
async def batch_check_emails(emails):
as_client = get_httpx_client()
tasks = [is_email_registered(as_client, email) for email in emails]
results = await asyncio.gather(*tasks, return_exceptions=True)
return dict(zip(emails, results))
示例代码参考:examples/email_registered.py
技巧二:Cookie池构建与轮换
Google通过Cookie跟踪用户会话,单一Cookie频繁请求极易触发风控。解决方案是构建Cookie池,实现请求时自动轮换。核心实现位于ghunt/objects/session.py,通过GHuntCreds类管理多个认证会话。
class CookiePool:
def __init__(self, cookie_files):
self.creds_list = [GHuntCreds().load_from_file(f) for f in cookie_files]
self.index = 0
def get_next_creds(self):
"""循环获取下一个Cookie会话"""
self.index = (self.index + 1) % len(self.creds_list)
return self.creds_list[self.index]
使用方法:
- 通过
ghunt login生成多个Cookie文件 - 初始化CookiePool并在每次请求前获取新会话
- 结合异步客户端实现会话隔离
技巧三:模块化任务调度与数据持久化
对于大规模采集任务,需要实现任务调度、失败重试和数据持久化。GHunt的模块化设计允许灵活组合不同API,例如结合ghunt/modules/email.py和ghunt/apis/peoplepa.py实现完整的用户相关信息采集。
async def scheduled_scan(emails, output_file, interval=60):
pool = CookiePool(["cookie1.json", "cookie2.json"])
for email_batch in chunkify(emails, 5): # 每批5个邮箱
creds = pool.get_next_creds()
results = await batch_collect_profile(creds, email_batch)
save_results(results, output_file)
await asyncio.sleep(interval) # 间隔60秒避免触发频率限制
任务流程图:
完整实现代码示例
结合以上技巧,以下是一个批量采集邮箱相关状态的完整脚本:
import asyncio
import json
from ghunt.helpers.gmail import is_email_registered
from ghunt.helpers.utils import chunkify, get_httpx_client
class BatchChecker:
def __init__(self, concurrency=5, interval=10):
self.concurrency = concurrency
self.interval = interval
async def check_batch(self, emails):
as_client = get_httpx_client()
tasks = [is_email_registered(as_client, email) for email in emails]
results = await asyncio.gather(*tasks, return_exceptions=True)
await as_client.aclose()
return {e: r for e, r in zip(emails, results)}
async def run(self, emails, output_file):
for batch in chunkify(emails, self.concurrency):
results = await self.check_batch(batch)
with open(output_file, 'a') as f:
json.dump(results, f)
f.write('\n')
print(f"Processed {len(batch)} entries, waiting...")
await asyncio.sleep(self.interval)
if __name__ == "__main__":
emails = ["test1@gmail.com", "test2@gmail.com"] # 实际使用时从文件读取
checker = BatchChecker(concurrency=3, interval=15)
asyncio.run(checker.run(emails, "results.json"))
注意事项与最佳实践
- 请求频率控制:根据Google的API限制,建议每IP每分钟不超过60次请求
- 错误处理:实现指数退避重试机制处理临时失败
- Cookie管理:定期更新Cookie池,避免长期使用同一组Cookie
- 数据存储:采用JSONL格式(每行一个JSON对象)便于增量处理
总结与展望
通过异步并发、Cookie池和模块化调度三大技巧,可以有效突破Google的API限制,实现高效的批量数据采集。GHunt作为一个活跃发展的框架,其examples目录和ghunt/apis模块提供了丰富的扩展可能。未来版本可能会集成更智能的请求调度和反检测机制,进一步提升采集效率。
建议收藏本文并关注项目更新,下期将介绍如何结合GHunt和机器学习进行用户相关信息分析。
【免费下载链接】GHunt 🕵️♂️ Offensive Google framework. 项目地址: https://gitcode.com/GitHub_Trending/gh/GHunt
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考




