Metadata-Version: 2.5
Name: beian
Version: 0.2.0
Summary: Query ICP beian like whois
Project-URL: Homepage, https://github.com/Gowee/beian-cli
Project-URL: Repository, https://github.com/Gowee/beian-cli
Project-URL: Issues, https://github.com/Gowee/beian-cli/issues
Author-email: Hung-I WANG <whygowe@gmail.com>
License-Expression: GPL-2.0-or-later
License-File: LICENSE
Keywords: beian,icp,miit,备案,查询
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Internet
Classifier: Topic :: Security
Requires-Python: >=3.10
Requires-Dist: ddddocr>=1.6.1
Requires-Dist: playwright~=1.61.0
Requires-Dist: requests>=2.31
Description-Content-Type: text/markdown

# beian

> Query ICP beian like whois

[![vibed](https://img.shields.io/badge/100%25-vibed-blue)](https://github.com)

Query ICP registration info from MIIT's official system. Solves CAPTCHA automatically.

## Install

```bash
uvx beian --help
```

Or install permanently:

```bash
uv tool install beian
```

## Browser Setup

ICP filing queries drive a real browser under the hood. On first use `beian`
picks a browser automatically:

1. **System Chrome / Edge** (if installed) — zero download, most authentic.
2. **Playwright-managed Chromium** — downloaded by Playwright itself into
   its own cache on first use (~380 MB). Runs via the `chromium` channel
   (new headless mode), so one binary serves both headless and headed
   (`--no-headless`) runs.

No manual download step needed in the common case. You can pre-install it:

```bash
uvx --from beian python -m playwright install --no-shell chromium
```

Policy flags (env):

| Env | Values | Meaning |
|-----|--------|---------|
| `BEIAN_BROWSER` | `auto` (default), `system`, `managed` | Force system browser or Playwright-managed browser |
| `BEIAN_SKIP_BROWSER_DOWNLOAD` | `1` | Never download; error with instructions instead |

Notes:
- The managed browser uses Playwright's **new headless mode** (real full
  Chromium), which is more authentic and reliable than the legacy headless shell.
- The downloaded browser is cached by Playwright and reused on later runs.

## Usage

```bash
# ICP filing (default)
beian baidu.com
beian "北京百度网讯科技有限公司"

# ICP license (增值电信业务经营许可证)
beian --license "小米科技有限责任公司"

# App / miniprogram / quick app
beian --app "微信"
beian --miniprogram "人民法院在线服务"
beian --quickapp "计算器"

# Batch query
beian baidu.com qq.com taobao.com

# JSON output
beian --raw baidu.com

# Screenshot (ICP filing only)
beian --screenshot baidu.com

# Verbose progress
beian -v baidu.com

# Custom retry count
beian --retry 10 "小米科技有限责任公司"
```

## Query Types

| Flag | Type | Source |
|------|------|--------|
| (default) | ICP filing — website (备案) | beian.miit.gov.cn |
| `--app` | ICP filing — app (备案) | beian.miit.gov.cn |
| `--miniprogram` | ICP filing — miniprogram (备案) | beian.miit.gov.cn |
| `--quickapp` | ICP filing — quick app (备案) | beian.miit.gov.cn |
| `--license` | ICP license (许可证) | tsm.miit.gov.cn |

## ICP License Features

The `--license` query automatically fetches:
- License info (许可证信息)
- Business types and scope (业务种类及覆盖范围)
- Authorization info (授权信息)
- Annual report (年报公示)

## How It Works

**ICP filing**: Uses Playwright to control a headless browser, solves slider CAPTCHA via gap detection algorithm (~67% first-try success rate).

**ICP license**: Uses `ddddocr` with edge enhancement preprocessing to solve text CAPTCHA (~12% per attempt, ~100% with retries).

## Development

```bash
uv sync
uv run python -m beian.cli --help
```

## License

GPL 2.0 or later
