Prompt

How do I collect training data for machine learning from websites?

Latest observation

Jul 15, 2026 · OpenAI APIWeb search: off

Collecting training data from websites usually means web scraping or using an official API to gather text, images, tables, product info, etc. The safest and most reliable approach is to use sources that explicitly allow reuse.

1) Prefer official APIs and open datasets

Before scraping, check whether the site provides:

  • An API
  • A bulk download
  • A public dataset on places like Kaggle, data portals, or GitHub

This is usually:

  • More stable
  • Better structured
  • Less likely to violate terms of service

2) Check legal and site rules

Before collecting anything, review:

  • Terms of Service
  • robots.txt
  • Copyright/licensing terms
  • Privacy rules, especially for personal data

Important:

  • robots.txt is not a legal permission slip, but it tells you what automated access the site prefers.
  • Avoid collecting personal data unless you have a clear lawful basis and compliance plan.

3) Decide what data you need

Define:

  • Input features
  • Labels/targets
  • Format needed for training
  • How many samples you need
  • Whether the data is text, images, HTML tables, etc.

Example:

  • For sentiment analysis: article text + sentiment label
  • For product prediction: product title, price, category, rating

4) Use the right collection method

Common options:

a) Requests + HTML parsing

Good for static pages. Tools:

  • requests
  • BeautifulSoup
  • lxml

b) Browser automation

Good for pages rendered by JavaScript. Tools:

  • Selenium
  • Playwright

c) Site APIs

Best when available. Tools:

  • requests, httpx, SDKs

5) Be polite and reliable

If scraping:

  • Rate limit requests
  • Use reasonable delays
  • Respect authentication and access restrictions
  • Don’t overload servers
  • Identify your crawler in the user-agent if appropriate

6) Clean and structure the data

After collecting:

  • Remove duplicates
  • Handle missing values
  • Normalize text
  • Parse dates/numbers
  • Store labels consistently

Typical storage:

  • CSV
  • JSONL
  • Parquet
  • SQL database
  • Object storage for images

7) Label the data

If your training task needs labels:

  • Use existing metadata when possible
  • Build annotation workflows
  • Use human labeling tools like Label Studio, Prodigy, or custom forms

8) Save provenance

Track:

  • Source URL
  • Timestamp
  • Collection method
  • License/usage rights
  • Version of the page

This helps with reproducibility and compliance.

9) Example workflow

  1. Find a website with data you need
  2. Check API / terms / robots.txt
  3. Decide fields to collect
  4. Write a scraper or API client
  5. Save raw data
  6. Clean and normalize it
  7. Label it if needed
  8. Split into train/validation/test sets

10) Tiny example with Python

For a simple static page:

import requests
from bs4 import BeautifulSoup

url = "https://example.com"
html = requests.get(url, timeout=10).text
soup = BeautifulSoup(html, "html.parser")

titles = [h.get_text(strip=True) for h in soup.find_all("h1")]
print(titles)

11) Best practices

  • Prefer open, licensed data
  • Avoid personal or sensitive data
  • Keep audit logs
  • Build automated checks for schema changes
  • Don’t rely on scraping if an API exists

If you want, I can also show you:

  • how to scrape a site step by step,
  • how to collect data with an API,
  • or how to build a dataset for a specific ML task like text classification or image recognition.

Observation history

Unlock observation history

Create a free Obsurfable account to unlock historical responses, model comparisons, and deeper brand intelligence.

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, and Meta AI.