0Pricing
Web Scraping & Bots · Pelajaran

Pembatasan Laju dan Perayapan yang Sopan

Pelajari cara membatasi laju permintaan, mematuhi crawl-delay, dan menghindari pembebanan server secara berlebihan agar scraping Anda tetap etis dan berkelanjutan.

Pembatasan Laju dan Perayapan yang Sopan adalah pelajaran Web Scraping & Bots gratis di CoddyKit. Ini adalah pelajaran 4 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Web Scraping & Bots, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Web Scraping & Bots mencakup 4 pelajaran total.

Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.

Why Rate Limiting Matters

Even when scraping is legally permitted, hammering a server with rapid requests can degrade the site for real users and get your IP banned.

Respectful crawling means pacing your requests so you gather data without harming the host.

The Cost of a Request

Every request consumes server CPU, bandwidth, and database load. A scraper firing hundreds of requests per second behaves like a denial-of-service attack, even unintentionally.

  • Small sites have limited capacity.
  • Bursts spike server load.
  • Steady, slow traffic is far kinder.

Reading Crawl-Delay

Many robots.txt files include a Crawl-delay directive specifying seconds to wait between requests. Honor it as a baseline minimum.

User-agent: *
Crawl-delay: 10
Disallow: /private/

A Simple Delay

The most basic throttle adds a pause between requests. A fixed delay is fine for low-volume jobs.

import time
import requests

for url in urls:
    requests.get(url)
    time.sleep(2)  # at least 2 seconds between requests

Randomized Delays

Fixed intervals create a robotic, easily-detected pattern. Adding jitter makes traffic look more human and spreads load.

import random, time

delay = random.uniform(1.5, 4.0)
time.sleep(delay)

Token Bucket Throttling

For steadier control, a token bucket permits a fixed average rate while allowing small bursts. Tokens refill over time; each request spends one.

import time

class RateLimiter:
    def __init__(self, rate):
        self.rate = rate
        self.last = time.time()
    def wait(self):
        now = time.time()
        gap = 1.0 / self.rate
        sleep = gap - (now - self.last)
        if sleep > 0:
            time.sleep(sleep)
        self.last = time.time()

Respecting HTTP 429

A 429 Too Many Requests response is the server telling you to slow down. Check for a Retry-After header and back off for that duration.

resp = requests.get(url)
if resp.status_code == 429:
    wait = int(resp.headers.get('Retry-After', 30))
    time.sleep(wait)

Exponential Backoff

On repeated errors, increase the wait exponentially rather than retrying immediately. This relieves a struggling server and improves your success rate.

delay = 1
for attempt in range(5):
    resp = requests.get(url)
    if resp.ok:
        break
    time.sleep(delay)
    delay *= 2  # 1, 2, 4, 8, 16 seconds

Concurrency Limits

Parallel requests speed things up but multiply server load. Cap simultaneous connections with a semaphore so you never exceed a polite ceiling.

import threading
sem = threading.Semaphore(4)  # max 4 in flight

def fetch(url):
    with sem:
        requests.get(url)

Scheduling Off-Peak

Run heavy jobs during the site's low-traffic hours (often overnight in the host's timezone). Combined with throttling, this minimizes your footprint and reduces the chance of disruption.

Caching to Avoid Re-Fetching

The kindest request is the one you never send. Cache responses locally so re-running a job does not re-hit pages you already have. Only fetch what is new or stale.

import os
if not os.path.exists(cache_path):
    resp = requests.get(url)
    open(cache_path, 'w').write(resp.text)
html = open(cache_path).read()

Quick Check

Test your understanding of respectful crawling.

Recap

You learned to crawl respectfully: honor Crawl-delay, add randomized delays, use token buckets, react to 429 with backoff, cap concurrency, and schedule off-peak.

Polite pacing keeps your scraper sustainable and your access intact.

Pertanyaan yang Sering Diajukan

Apakah pelajaran “Pembatasan Laju dan Perayapan yang Sopan” gratis?

Ya — teks lengkap “Pembatasan Laju dan Perayapan yang Sopan” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Web Scraping & Bots, upgrade ke CoddyKit PRO. Kursus Web Scraping & Bots mencakup 4 pelajaran total.

Apa yang akan aku pelajari di “Pembatasan Laju dan Perayapan yang Sopan”?

Pelajari cara membatasi laju permintaan, mematuhi crawl-delay, dan menghindari pembebanan server secara berlebihan agar scraping Anda tetap etis dan berkelanjutan. Kamu berlatih Web Scraping & Bots dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.

Apakah aku perlu pengalaman untuk memulai Web Scraping & Bots?

Tidak diperlukan pengalaman sebelumnya. Web Scraping & Bots di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 4 dari 4.

Berapa lama pelajaran “Pembatasan Laju dan Perayapan yang Sopan” memakan waktu?

Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.

Bisakah aku menulis dan menjalankan kode dalam pelajaran Web Scraping & Bots ini?

Ya. Setiap pelajaran Web Scraping & Bots menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.

Semua pelajaran dalam kursus ini

  1. Memahami Robots.txt
  2. Ketentuan Layanan dan Hak Cipta
  3. Praktik Scraping yang Etis
  4. Pembatasan Laju dan Perayapan yang Sopan
← Kembali ke Web Scraping & Bots