Skip to content

Use StackExchange API as default search backend#518

Open
gleitz wants to merge 5 commits intomasterfrom
fix/stackexchange-api-fallback
Open

Use StackExchange API as default search backend#518
gleitz wants to merge 5 commits intomasterfrom
fix/stackexchange-api-fallback

Conversation

@gleitz
Copy link
Copy Markdown
Owner

@gleitz gleitz commented Apr 14, 2026

Summary

  • Adds StackExchange API (/2.3/search/advanced) as the default search backend, replacing web scraping which is now blocked by Google, Bing, and DuckDuckGo
  • Falls back to scraping engines if the StackExchange API returns no results or errors
  • Updates user agents and consent cookies to modern values for scraping fallback
  • Adds additional Google consent page block indicators for better detection

Fixes #516. Also addresses #492 and #489 which have the same root cause (search engines blocking HTTP scraping).

Details

The core issue: all three supported search engines (Google, Bing, DuckDuckGo) now actively block the HTTP scraping that howdoi relies on. The StackExchange API provides 300 requests/day without authentication, which is more than sufficient for typical usage.

The HOWDOI_SEARCH_ENGINE env var still works — set it to google, bing, or duckduckgo to use scraping if preferred. Default is now stackexchange.

Test plan

  • howdoi print stack trace python returns results
  • howdoi format date bash returns results
  • howdoi convert json to csv python returns results
  • 23 tests passing (2 pre-existing failures unrelated to this change)
  • Verify HOWDOI_SEARCH_ENGINE=google fallback still works where Google isn't blocking

🤖 Generated with Claude Code

gleitz and others added 5 commits April 13, 2026 16:18
Google, Bing, and DuckDuckGo all now block HTTP scraping with
CAPTCHA/consent pages, making howdoi unable to find answers (fixes #516).

Switch to StackExchange API as the default search backend (300 free
requests/day, no auth needed). The scraping backends remain available
as fallbacks via HOWDOI_SEARCH_ENGINE env var.

Also: updated user agents to 2024-era browsers, added consent page
detection to block indicators, and made empty results trigger engine
fallback instead of silently returning nothing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Python 3.7 and 3.8 are no longer available on GitHub Actions runners.
Update checkout to v4 and setup-python to v5.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Break long USER_AGENTS lines and suppress E231/E713 false positives
from f-string colons and string literals.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
pylint 2.15.10 crashes on Python 3.12+ with `visit_typealias` error
in astroid. Upgrade to pylint 3.3.6 and flake8 7.1.2. Also fix
deprecated pylintrc option and exclude setup.py from pylint (distutils
removed in 3.12+).

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
- Change default search engine from 'google' to 'stackexchange' in
  howdoi() and _get_answers() to match _get_links() default
- Add force_terminal=True to Rich Console so ANSI color codes are
  always emitted when -c flag is used (fixes test_colorize)

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

doesnt work with any command

1 participant