将任意公开个人资料页面转换为结构化的账户记录——用户名、显示名称、个人简介、头像、位置、注册日期、粉丝数、外部链接,以及稳定内部标识符,这些标识符能在账户改名、改版和删除后依然唯一锁定该账户。
socid_extractor 解析来自 130+ 平台的 HTML 页面和 API 响应,返回一个扁平且机器可读的账户字段字典。无需 API 密钥,无需无头浏览器——只需对响应文本进行一次函数调用。
为什么它有用
extract() 调用——无需为每个平台编写胶水代码。username、fullname、created_at、is_verified 等),因此下游管道无需维护 130 种映射。Python: 3.10+。
pip install socid-extractor
若要在工作站上进行简洁的 CLI 安装:
pipx install socid-extractor
最新开发版本:
pip install -U git+https://github.com/soxoj/socid-extractor.git
作为 CLI 使用:
$ socid_extractor --url https://www.deviantart.com/muse1908
country: France
created_at: 2005-06-16 18:17:41
gender: female
username: Muse1908
website: www.patreon.com/musemercier
links: ['https://www.facebook.com/musemercier', 'https://www.instagram.com/muse.mercier/', 'https://www.patreon.com/musemercier']
tagline: Nothing worth having is easy...
作为 Python 库使用:
import requests
import socid_extractor
r = requests.get('https://www.patreon.com/annetlovart')
print(socid_extractor.extract(r.text))
# {'patreon_id': '33913189', 'patreon_username': 'annetlovart',
# 'fullname': 'Annet Lovart',
# 'links': "['https://www.facebook.com/322598031832479', ...]"}
提示——批量运行: 传递 --skip-fetch-if-no-url-hint 可在 URL 不匹配任何已知站点提示时跳过 HTTP 请求(速度更快,但可能跳过通用引擎,如论坛模板):
$ socid_extractor --url https://example.com/foo --skip-fetch-if-no-url-hint
非穷举示例:
……以及许多其他站点。
数据示例请参见 tests/test_e2e.py;解析逻辑请参见 socid_extractor/schemes.py;字段本体请参见 FIELDS.md。
开源版本的 socid_extractor 使用 MIT 许可证,可免费用于商业用途,无任何限制——但页面解析器会随着平台更改 HTML 和 API 而失效,因此需要主动维护。
对于严肃的商业用途——如果你需要维护的私有插件包(包含额外解析器)或托管提取 API——请联系:📧 [email protected]
socid_extractor 集成到你的产品中对应于以下 SOWEL 技术:
从 pyproject.toml 安装测试额外依赖,然后运行 pytest:
pip install '.[test]' # pytest, pytest-rerunfailures, pytest-xdist
python3 -m pytest tests/test_e2e.py -n 10 -k 'not cookies' -m 'not github_failed and not rate_limited'
如果你还想要 flake8 / mypy / black(CI 使用的完整工具集),请改用 pip install '.[dev]'。
每个新方案必须在 tests/test_e2e.py 中有一个 e2e 测试,命中真实的 URL/API。还需要包含内联 fixture 的单元测试(tests/test_socid_improvements.py),但这不替代 e2e 覆盖。详情请参阅 docs/testing-and-ci.md。
开发者文档(架构、模块、CI)位于 docs/。
如果你想添加新方案或修复任何问题,请参阅贡献指南。