diff --git a/ddgs/cli.py b/ddgs/cli.py index 390e8bfd..7994ec95 100644 --- a/ddgs/cli.py +++ b/ddgs/cli.py @@ -166,6 +166,13 @@ def cli() -> None: def safe_entry_point() -> None: """Run the CLI tool in try-except block to catch all exceptions.""" logging.basicConfig(level=logging.WARNING) + # Fix Windows GBK encoding issues by setting stdout to UTF-8 + if sys.platform == "win32" and hasattr(sys.stdout, "reconfigure"): + try: + sys.stdout.reconfigure(encoding="utf-8") + sys.stderr.reconfigure(encoding="utf-8") + except Exception: # noqa: BLE001 + pass # Fallback to original encoding if reconfigure fails try: cli() except Exception as ex: # noqa: BLE001 diff --git a/tests/cli_test.py b/tests/cli_test.py index dafbc271..f80674bc 100644 --- a/tests/cli_test.py +++ b/tests/cli_test.py @@ -45,6 +45,12 @@ def test_books_command() -> None: assert "title" in result.output +def test_extract_command() -> None: + result = runner.invoke(cli, ["extract", "-u", "https://www.technologyreview.com/2026/01/12/1130697/10-breakthrough-technologies-2026/"]) + assert result.exit_code == 0 + assert "Breakthrough" in result.output + + def test_text_workflow(tmp_path: Path) -> None: """Combined test for text search, save, and download functionality.""" # Step 1: Get text results