A Python script that interacts with ChatGPT using the ScrapingAnt API for browser rendering. It can submit prompts, optionally enable web search mode, and extract responses.
- Browser-based interaction with ChatGPT via ScrapingAnt API
- Optional web search mode toggle
- Configurable response wait time
- HTML response saved for debugging
- Command-line interface
- Python 3.7+
- ScrapingAnt API key
-
Clone this repository or download the files
-
Create a virtual environment (recommended):
python3 -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install dependencies:
pip install requests beautifulsoup4
-
Add your ScrapingAnt API key to
chatgpt_scraper.py:API_KEY = "<YOUR_SCRAPINGANT_API_KEY>"
- Go to ScrapingAnt
- Click Sign Up or Get Started Free
- Create an account using email or Google/GitHub OAuth
- After registration, navigate to your Dashboard
- Find your API key in the API Key section
- Copy the API key and paste it into
chatgpt_scraper.py
Note: ScrapingAnt offers a free tier with limited API credits. For production usage, consider upgrading to a paid plan.
python chatgpt_scraper.py "What is the capital of France?"python chatgpt_scraper.py "Explain quantum computing" --no-searchpython chatgpt_scraper.py "Write a poem about AI" --wait 45000python chatgpt_scraper.py --help| Argument | Description | Default |
|---|---|---|
prompt |
The prompt to send to ChatGPT | Required |
--no-search |
Disable web search mode | Enabled |
--wait |
Wait time for response in ms | 35000 |
The script will:
- Print the prompt and configuration
- Save the raw HTML response to
chatgpt_response.html - Print the extracted ChatGPT response
- Builds a JavaScript snippet to interact with ChatGPT's interface
- Sends request to ScrapingAnt API with browser rendering enabled
- JavaScript clicks search button (if enabled), inputs the prompt, and submits
- Waits for ChatGPT to generate a response
- Returns HTML which is parsed to extract the response text
- No response extracted: Increase
--waittime for longer responses - API errors: Verify your API key is correct and has available credits
- Empty responses: Check
chatgpt_response.htmlfor debugging
MIT License