Web Scraping Không Bị Block: 10 Kỹ Thuật Hiệu Quả (2026)
Websites ngày càng tinh vi trong việc phát hiện và block scrapers. Đây là guide đầy đủ để scraping mà không bị chặn.
Tại Sao Bị Block?
- Quá nhiều requests từ cùng IP
- Request patterns không giống người dùng
- Headers/fingerprint bất thường
- Thiếu JavaScript rendering
1. Sử Dụng Proxy
Rotate IP
Dùng nhiều IP khác nhau để requests trông như từ nhiều users:
# Python với requests
proxies = {
'http': 'http://user:pass@proxy.vinaproxy.com:8080',
'https': 'http://user:pass@proxy.vinaproxy.com:8080'
}
response = requests.get(url, proxies=proxies)
Residential vs Datacenter
| Loại | Detection Risk | Use Case |
|---|---|---|
| Datacenter | Cao | Targets dễ |
| Residential | Thấp | Targets khó (Amazon, Google) |
| Mobile 4G/5G | Rất thấp | Social media |
2. Headless Browser
Render JavaScript như browser thật:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
opts = Options()
opts.add_argument("--headless")
driver = webdriver.Chrome(options=opts)
driver.get(url)
3. Giả Lập User Agent
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
}
response = requests.get(url, headers=headers)
4. Random Delays
import time
import random
time.sleep(random.uniform(1, 3)) # 1-3 giây ngẫu nhiên
5. Xử Lý Cookies
session = requests.Session()
session.get('https://target.com') # Lấy cookies
response = session.get('https://target.com/data') # Dùng cookies
6. Respect robots.txt
Không scrape quá nhanh, tôn trọng rate limits.
7. Bypass Cloudflare
- Dùng undetected_chromedriver
- Puppeteer-extra với stealth plugin
- Scrape cached version
8. Tránh Honeypots
Một số sites đặt links ẩn để bẫy bots. Check CSS display:none trước khi click.
9. Manage Sessions
Giữ session consistent như user thật – đừng đổi fingerprint giữa chừng.
10. Monitor & Adapt
Theo dõi success rate, điều chỉnh strategy khi bị block.
VinaProxy – Giải Pháp Không Bị Block
- Residential IP từ ISP thật
- Auto-rotation tránh detection
- Hỗ trợ HTTP/HTTPS/SOCKS5
- Giá chỉ $0.5/GB
