oxylabs/chatgpt-scraper
关于
只需提供提示词和有效的 Web Scraper API 凭据,即可轻松收集 ChatGPT scraper 的响应。
人工智能与机器学习实测星标增长
- 24小时
- +2
- 7天
- +7
- 15天
- -25
- 1个月
- -3
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文ChatGPT Scraper
The ChatGPT Scraper by Oxylabs allows you to send prompts to ChatGPT and automatically collect both conversational responses and structured metadata. You can use the Web API with ChatGPT for SEO monitoring, AI response analysis, and brand presence tracking. It provides parsed, ready-to-use JSON output without the need to manage proxies and browsers, or avoid server-side defense systems.
How Oxylabs ChatGPT Scraper works
ChatGPT isn't a static web page. It's an app built on dynamic content: the model's answer streams in after the page loads, and citations, product cards, and images appear alongside it. Scraping ChatGPT with general web scraping tools means you have to run a headless browser, manage rotating proxies, write a CSS selector or an XPath selector for every element, and fix them each time the layout changes.
The ChatGPT scraper replaces all of that with a single API endpoint. You send a prompt, Web API loads and renders the ChatGPT page, and its built-in parser returns the answer as structured data – plain text, Markdown, citations, and more. There is no target page to look up, no HTML to parse, and no selector to maintain, so you can scrape ChatGPT data at scale with a few lines of code.
Compared with a typical web scraping project, here is all a request involves:
- Get an API key. In the Oxylabs dashboard, create a Web API instance and generate an API key on it. Every request sends that key as a Bearer token.
- Submit a job. Send a POST request to
/v1/async/scrape/chatgptwith your prompt inqueryandoutputset to["json"]. The API replies with a job ID inmetadata.request_id. - Collect the result. Poll
GET /v1/async/scrape/{request_id}until the job is no longerpending, or let the API post the finished job to yourcallback_url. - Read the answer. The parsed ChatGPT response comes back as structured JSON under
results[0].json. If a job fails, its state isfaultedand the response describes the error.
The ChatGPT scraper is asynchronous: there is no realtime path, so every request creates a job that you collect when it's done.
[!TIP] To evaluate our products before purchasing, you may request a free trial by submitting an inquiry. Free trials are subject to approval and involve no upfront commitment.
Request sample (Python)
First, install the Python requests library:
pip install requests
Then save your API key in an environment variable, so you never write it into your code, and create the following .py file:
export OXYLABS_WEB_API_KEY=your_api_key_here
import os
import time
import requests
API = 'https://webapi.oxylabs.io'
HEADERS = {'Authorization': f"Bearer {os.environ['OXYLABS_WEB_API_KEY']}"}
# Structure payload.
payload = {
'query': 'best supplements for better sleep',
'search': True,
'location': 'US',
'output': ['json'],
}
# Submit the job.
job = requests.post(f'{API}/v1/async/scrape/chatgpt', headers=HEADERS, json=payload, timeout=60)
job.raise_for_status()
job_id = job.json()['metadata']['request_id']
# Poll with a GET request until the job is no longer pending.
while True:
result = requests.get(f'{API}/v1/async/scrape/{job_id}', headers=HEADERS, timeout=60).json()
if result['state'] != 'pending':
break
time.sleep(10)
# Print the ChatGPT answer as Markdown.
print(result['results'][0]['json']['markdown_text'])
The code submits your prompt to the ChatGPT scraper, polls until the job is done, and prints the answer. You can find code examples for other programming languages here.
Request parameters
| Parameter | Description | Type |
|---|---|---|
query * |
The prompt to send to ChatGPT. Up to 4,000 characters. | string |
search |
true lets ChatGPT browse the web for current information and cite it. false answers from the model's training data only. |
boolean |
output |
Formats to return: json, markdown, html, screenshot. Default ["html"]. Use json for the parsed fields. |
array of strings |
json |
Custom extraction with {"prompt": string} or {"schema": object}, never both. Overrides the built-in parser. |
object |
location |
Two-letter country code to send the prompt from, e.g. US or DE. |
string |
device |
desktop (default) or mobile. |
string |
callback_url |
Webhook URL the finished job is posted to. | string |
storage |
Delivers the result to your bucket: {"type": string, "url": string}. type is s3, s3_gzip, s3_compatible, gcs, or tos. |
object |
* – mandatory parameter
Check out the ChatGPT scraper reference to learn more.
Output samples
JSON example
Below is a trimmed sample of the structured JSON output for the request above. You can find the full output example file in this repository.
{
"state": "done",
"results": [
{
"json": {
"prompt": "best supplements for better sleep",
"response_text": "If your goal is to fall asleep faster, stay asleep longer, and wake up feeling refreshed, there are a few supplements worth knowing about. ...",
"markdown_text": "If your goal is to fall asleep faster, stay asleep longer, and wake up feeling refreshed, there are a few supplements worth knowing about.\n\n...",
"markdown_json": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"raw": "If your goal is to fall asleep faster, stay asleep longer, and wake up feeling refreshed, there are a few supplements worth knowing about."
}
]
},
{
"type": "blank_line"
},
...
],
"citations": [
{
"title": "Insomnia - Diagnosis and treatment",
"url": "https://www.mayoclinic.org/diseases-conditions/insomnia/diagnosis-treatment/drc-20355173?utm_source=chatgpt.com",
"text": "Mayo Clinic",
"domain": "mayoclinic.org",
"source": "text"
},
...
],
"images": [...],
"ads": [...],
"raw_response": [...]
},
"metadata": {
"url": "https://chatgpt.com/uc/6b12c44e-248c-83ea-9167-4d687049f54b",
"statuses": {
"http_request": { "code": 200 },
"json_parse": { "code": 12000 }
}
}
}
],
"params": {
"query": "best supplements for better sleep",
"search": true,
"location": "US",
"output": ["json"],
"device": "desktop"
},
"metadata": {
"timestamp": 1796392052,
"request_id": "7534614157836988417"
}
}
Markdown and HTML
For AI tools that consume ChatGPT responses, the markdown_text field holds the answer as clean text in Markdown. You can also request output: ["markdown"], but note that it converts the whole ChatGPT page, not only the answer. To get the page source, set output to ["html"]:

Note: The composition of elements may vary depending on whether the query was made from a desktop or mobile device.
JSON output structure
The ChatGPT scraper returns the standard Web API envelope, with the parsed ChatGPT fields in the results array. The tables below explain each element, its description, and its data type.
Response envelope
| Key Name | Description | Type |
|---|---|---|
state |
pending while the job runs, done when it's finished, faulted if it failed. |
string |
results[].json |
Parsed ChatGPT response, if requested. | object |
results[].markdown |
The ChatGPT page as Markdown, if requested. | string |
results[].html |
The ChatGPT page source, if requested. | string |
results[].metadata.url |
The ChatGPT conversation the answer came from. | string |
results[].metadata.statuses.http_request.code |
HTTP status code of the page request, 200 on success. |
integer |
results[].metadata.statuses.json_parse.code |
12000 – successful parse. Otherwise, the parser failed to extract some or all structured fields. |
integer |
params |
The request as executed, with defaults filled in. | object |
metadata.timestamp |
Unix timestamp in seconds. | integer |
metadata.request_id |
The job ID. Include it in support tickets. | string |
ChatGPT-specific fields
Note: The number of items and fields for a specific result type may vary depending on the submitted prompt.
| Key Name | Description | Type |
|---|---|---|
prompt |
Submitted prompt to generate result. | string |
response_text |
Plain-text response from ChatGPT. | string |
markdown_text |
ChatGPT response as Markdown. | string |
markdown_json |
Structured JSON representation of the Markdown response. Each item contains type, children, and raw. |
array |
* citations |
Sources related to the answer, the images, products, and offers. Objects contain url, title, text (site name as shown by ChatGPT), domain (website without www., e.g. rtings.com), and source. |
array |
* citations[].source |
Source type: text – cited in the answer, search – read during web search but not cited, images – page an image comes from, shopping – product card store, offers – product offer store. |
string |
* links |
Inline links in the answer: each link's url and text. |
array |
* images |
Images shown in the answer, including product images and photo galleries: title, image_url, thumbnail_url, description (the search phrase ChatGPT used to find the image), and citations. |
array |
* shopping_products |
Products ChatGPT recommends, as shown on the product cards in the answer: title, url, price (the product price as a number), price_str (the price as displayed), currency, merchant, badge, description, rating, reviews_count, thumbnail, images, image_page_title, image_page_url, offers, and citations. |
array |
* shopping_products[].offers |
Merchant offers for the product: merchant, price, price_str, currency, url, and details (availability and delivery details, as displayed). |
array |
* shopping_products[].citations |
Sources cited for the product: source (website or publication name), title, and url. |
array |
* ads |
Sponsored ads shown with the answer: ad_type (product when the ad shows a price, text otherwise), heading (the short line ChatGPT shows above the ad), title, description, url, image_url, and advertiser_info. Product ads add price, price_str, currency, and, when on sale, price_strikethrough and price_strikethrough_str. |
array |
* ads[].advertiser_info |
Advertiser name, url, and logo: image_data (base64, when embedded) or image_url (when linked). |
object |
raw_response |
Raw streamed response from ChatGPT, one line per item. | array of strings |
* – conditional, returned only when content is in the LLM's response. Fields ChatGPT doesn't show for a given prompt are left out, so missing fields are expected and don't need a fix on your side.
Responses may differ between identical requests, since the model's answers vary, and parsed fields follow ChatGPT's current layout, so they can change when ChatGPT changes it.
Custom extraction with AI parsing
If the built-in fields aren't the shape your code needs, add a custom extraction object with a natural-language prompt or a schema. Web API will then extract exactly those data fields instead of the built-in ones – still no CSS selectors to write. For example, to extract brand mentions for brand monitoring:
{
"query": "best supplements for better sleep",
"output": ["json"],
"json": {
"schema": {
"type": "object",
"properties": {
"brands": {
"type": "array",
"items": { "type": "string" },
"description": "Supplement brands named in the answer, in order of appearance"
}
},
"required": ["brands"]
}
}
}
AI parsing uses significantly more account credit than the built-in parser. See AI Parsing for schema patterns.
Scale up with batch requests and delivery
Web API delivers ChatGPT results in two ways, so you can start with one prompt and scale to thousands with the same code – no queue to build, as you would for a DIY web scraper:
| Mode | Endpoint | Max prompts per request | Best for |
|---|---|---|---|
| Async single | POST /v1/async/scrape/chatgpt |
1 | Single prompts and testing |
| Async batch | POST /v1/async/scrape/batch/chatgpt |
5,000 | Bulk prompt sets |
Each job's data can be collected by polling, posted to your callback_url, or written straight to your own cloud storage bucket with storage. The storage destination is not validated, so test it with a single request before you run a batch.
Save ChatGPT responses to a CSV file
The example below sends a batch of prompts, collects each job, and writes the answers and the sites ChatGPT cited to chatgpt_responses.csv – a simple starting point for a data pipeline that tracks ChatGPT responses over time:
import csv
import os
import time
import requests
API = 'https://webapi.oxylabs.io'
HEADERS = {'Authorization': f"Bearer {os.environ['OXYLABS_WEB_API_KEY']}"}
prompts = [
'best supplements for better sleep',
'best magnesium supplement brands',
]
# Submit all prompts in one batch. Each accepted prompt becomes its own job.
batch = requests.post(
f'{API}/v1/async/scrape/batch/chatgpt',
headers=HEADERS,
json={'query': prompts, 'search': True, 'output': ['json']},
timeout=60,
)
batch.raise_for_status()
job_ids = [job['metadata']['request_id'] for job in batch.json().get('data', [])]
with open('chatgpt_responses.csv', 'w', newline='', encoding='utf-8') as file:
writer = csv.writer(file)
writer.writerow(['prompt', 'answer', 'cited_domains'])
for job_id in job_ids:
# Poll each job until it is no longer pending.
while True:
result = requests.get(f'{API}/v1/async/scrape/{job_id}', headers=HEADERS, timeout=60).json()
if result['state'] != 'pending':
break
time.sleep(10)
if result['state'] != 'done':
print(f"Job {job_id} ended as {result['state']}, skipping.")
continue
answer = result['results'][0]['json']
cited = sorted({c['domain'] for c in answer.get('citations', []) if c.get('source') == 'text'})
writer.writerow([answer['prompt'], answer['response_text'], ', '.join(cited)])
Prompts the API rejects, such as one over 4,000 characters, are listed in the batch response's errors array instead of data. See the Delivery Modes documentation for polling, callbacks, and storage details.
Use with AI agents
Web API works with AI agents as well as scripts, so an agent can handle scraping ChatGPT on its own. Install the Agent Skills with one command:
npx skills add oxylabs/web-api-skills
The MCP server adds typed tools on top, and the two work together. To check the current endpoints and parameters at runtime instead of hardcoding them, call GET /v1/scrapers, or send OPTIONS to an endpoint.
Practical use cases
This ChatGPT scraper API opens a wide range of opportunities for developers and data-focused teams who'd rather not run their own web scraping infrastructure.
- Building AI training datasets: Collect diverse, real-world conversational data at scale for training or fine-tuning Large Language Models (LLMs).
- SEO & competitor analysis: Monitor how competitors' brands and keywords are represented in AI-generated search results, and which websites ChatGPT cites for them.
- Brand presence management: Use brand monitoring to track your brand mentions and content rankings in ChatGPT answers and optimize your visibility strategies.
Why choose Oxylabs?
- Maintenance-free: Our API handles all the infrastructure, from proxy management to IP rotation and bot traffic management systems. This means you don't need to spend engineering time on maintenance or adapting to website changes.
- High success rates: Built on our industry-leading infrastructure, the API ensures a high degree of reliability and a consistent data flow for all your web scraping tasks.
- Advanced features: The API renders ChatGPT in a headless browser, handles server-side traffic challenges, offers geo-targeting with
locationto retrieve localized responses, and adds AI parsing, webhooks, cloud storage delivery, and batches of up to 5,000 prompts.
FAQ
Is scraping ChatGPT legal?
The legality of using ChatGPT scrapers depends on the way it is done and the applicable jurisdiction. While Oxylabs provides the infrastructure to collect publicly available or user-submitted data from ChatGPT, it is the responsibility of the user to ensure compliance with OpenAI's Terms of Service and local regulations.
What's the ChatGPT prompt size limit?
The maximum prompt length supported by the ChatGPT Scraper is 4,000 characters. Longer prompts are rejected with a 400 error before a job is created. If your use case requires handling longer inputs, consider splitting the text into smaller chunks and sending multiple sequential requests.
Learn more
For a deeper dive into available parameters, advanced integrations, and additional examples, check out the ChatGPT Scraper documentation and the Web API repository to see how to scrape other targets and use Web API for web scraping beyond ChatGPT.
Contact us
If you have questions or need support, reach out to us at [email protected], or through live chat, accessible via Oxylabs Dashboard, or join our Discord community. For enterprise-related inquiries, contact your dedicated account manager.
探索相关项目
加载中…
