Framework tự động hóa
Cách kết nối cho Selenium, Puppeteer, Playwright, Scrapy và các framework tự động hóa/thu thập dữ liệu khác. Mọi ví dụ chỉ cần thay USERNAME, PASSWORD bằng thông tin xác thực của bạn là chạy được.
Scrapy
Bật middleware proxy trong settings.py, hoặc thiết lập theo từng request:
# Cách 1: toàn cục (settings.py)
HTTPPROXY_ENABLED = True
# Chỉ định proxy cho từng request trong Spider
def start_requests(self):
proxy = "http://USERNAME-pool-flow-region-US:[email protected]:23333"
for url in self.start_urls:
yield scrapy.Request(url, meta={"proxy": proxy})
Xoay IP theo từng request là hành vi mặc định, phù hợp tự nhiên với mô hình chạy song song của Scrapy; khi cần cố định IP theo phiên, hãy thêm sid vào username.
Selenium (Python)
Tham số dòng lệnh của Chrome không hỗ trợ proxy có xác thực, nên khuyến nghị dùng selenium-wire để xử lý tài khoản/mật khẩu:
# pip install selenium-wire
from seleniumwire import webdriver
options = {
"proxy": {
"http": "http://USERNAME-pool-flow-region-US:[email protected]:23333",
"https": "http://USERNAME-pool-flow-region-US:[email protected]:23333",
}
}
driver = webdriver.Chrome(seleniumwire_options=options)
driver.get("https://ipinfo.io")
print(driver.page_source)
driver.quit()
Bạn cũng có thể chuyển sang chế độ danh sách trắng: sau khi trích xuất danh sách IP:cổng không cần xác thực, dùng trực tiếp tham số --proxy-server nguyên bản.
Puppeteer (Node.js)
const puppeteer = require("puppeteer");
(async () => {
const browser = await puppeteer.launch({
args: ["--proxy-server=http://proxy.eproxies.net:23333"],
});
const page = await browser.newPage();
await page.authenticate({
username: "USERNAME-pool-flow-region-US",
password: "PASSWORD",
});
await page.goto("https://ipinfo.io/json");
console.log(await page.evaluate(() => document.body.innerText));
await browser.close();
})();
Playwright (Node.js / Python)
// Node.js
const { chromium } = require("playwright");
(async () => {
const browser = await chromium.launch({
proxy: {
server: "http://proxy.eproxies.net:23333",
username: "USERNAME-pool-flow-region-US",
password: "PASSWORD",
},
});
const page = await browser.newPage();
await page.goto("https://ipinfo.io/json");
console.log(await page.textContent("body"));
await browser.close();
})();
# Python
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(proxy={
"server": "http://proxy.eproxies.net:23333",
"username": "USERNAME-pool-flow-region-US",
"password": "PASSWORD",
})
page = browser.new_page()
page.goto("https://ipinfo.io/json")
print(page.text_content("body"))
browser.close()
AI Agent / pipeline dữ liệu LLM
Khi dùng LLM điều khiển trình duyệt hoặc thu thập dữ liệu (công cụ LangChain, Browser Use, agent tự phát triển, v.v.), chỉ cần truyền cấu hình proxy của bất kỳ framework nào ở trên vào là được. Những điểm chính:
- Cấp cho mỗi agent chạy song song một
sidriêng, không ảnh hưởng lẫn nhau (ví dụ đa phiên). - Cho agent gọi
https://ipinfo.iođể kiểm tra IP đầu ra khi bắt đầu tác vụ, rồi mới thực thi nghiệp vụ. - Toàn bộ cú pháp tham số gói gọn trong một trang: Bảng tra cứu nhanh cho Agent.
Công cụ thu thập dữ liệu
Hướng dẫn cấu hình chính thức cho các công cụ thu thập dạng đồ họa: Octoparse · Scrapy · ScrapeStorm · SellerSprite · Helium 10
