なぜGoogle検索結果を検索しますか?
Google は 1 日あたりの 8.5 億件の検索を処理し、検索エンジンの結果ページ (SERPs) を Web で競争力のあるインテリジェンスの最も貴重なソースにします。 Google検索結果のスクレイピングは、オーガニックランキング、注目のスニペット、ピープルもチェックボックス、ローカルパック、および有料広告のプレースにリアルタイムでアクセスできます。
あなたが構築しているかどうか SERPモニタリングパイプライン またはワンオフキーワードの研究を実行したり、Google結果へのプログラム的なアクセスは、手動で完了するために時間を取るワークフローを自動化することができます。 共通の使用例は下記のものを含んでいます:
- 市場全体で独自のキーワードランキングを追跡
- ターゲットクエリの競合者の可視性を監視
- SERPの機能分布の分析(スニペット、画像、動画)
- SEOの研究とコンテンツ戦略のためのデータセットの構築
Google SERP構造の理解
スクレーパーを書く前に、Google結果ページの解剖学を理解する必要があります。 現代のSERPは、数十種類の異なる結果タイプを含むことができます。
| 結果タイプ | CSS/データマーカー | コンテンツ |
|---|---|---|
| 有機性結果 | div#search .g | タイトル、URL、スニペットによる標準的なブルーリンク結果 |
| おすすめスニペット | div.xpdopen | オーガニック結果の上に表示されている回答ボックス |
| 人々はまた尋ねます | div.related-question-pair | よくある質問 |
| ローカルパック | div.VkpGBb | ローカルビジネスリスト3社の地図 |
| ナレッジパネル | div.kp-wholepage | エンティティティ情報サイドバー |
| 広告結果 | div.uEierd | トップとボトムの有料検索広告 |
Googleはクラス名を頻繁に変更します。 フォールバックセレクターでパーサをビルドし、抽出を信頼性に保つために定期的にテストします。
あなたのスクレイピング環境の設定
Googleを確実にスクレイピングするには、HTTPクライアント、プロキシ接続、HTMLパーサーの3つのコンポーネントが必要です。 以下は、Python、Node.js、およびGoの使用に関する完全な例です。 ProxyHatプロキシ. .
Python の例
依存関係を最初にインストールします。 ザ・オブ・ザ・ ProxyHatのPython SDK プロキシ構成を簡素化します。
pip install requests beautifulsoup4import requests
from bs4 import BeautifulSoup
proxy_url = "http://USERNAME:PASSWORD@gate.proxyhat.com:8080"
proxies = {
"http": proxy_url,
"https": proxy_url,
}
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
"Accept-Language": "en-US,en;q=0.9",
}
def scrape_google(query, num_results=10):
params = {
"q": query,
"num": num_results,
"hl": "en",
"gl": "us",
}
response = requests.get(
"https://www.google.com/search",
params=params,
headers=headers,
proxies=proxies,
timeout=15,
)
response.raise_for_status()
soup = BeautifulSoup(response.text, "html.parser")
results = []
for g in soup.select("div#search .g"):
title_el = g.select_one("h3")
link_el = g.select_one("a")
snippet_el = g.select_one(".VwiC3b")
if title_el and link_el:
results.append({
"title": title_el.get_text(),
"url": link_el["href"],
"snippet": snippet_el.get_text() if snippet_el else "",
})
return results
results = scrape_google("best residential proxies 2026")
for i, r in enumerate(results, 1):
print(f"{i}. {r['title']}\n {r['url']}\n")Node.js 例
使い方 ProxyHat ノード SDK パースのためのチェリオ:
npm install axios cheerio https-proxy-agentconst axios = require('axios');
const cheerio = require('cheerio');
const { HttpsProxyAgent } = require('https-proxy-agent');
const agent = new HttpsProxyAgent('http://USERNAME:PASSWORD@gate.proxyhat.com:8080');
async function scrapeGoogle(query) {
const { data } = await axios.get('https://www.google.com/search', {
params: { q: query, num: 10, hl: 'en', gl: 'us' },
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
'Accept-Language': 'en-US,en;q=0.9',
},
httpsAgent: agent,
timeout: 15000,
});
const $ = cheerio.load(data);
const results = [];
$('div#search .g').each((i, el) => {
const title = $(el).find('h3').text();
const url = $(el).find('a').attr('href');
const snippet = $(el).find('.VwiC3b').text();
if (title && url) {
results.push({ position: i + 1, title, url, snippet });
}
});
return results;
}
scrapeGoogle('best residential proxies 2026').then(console.log);導入事例
使い方 ProxyHat ゴー SDK そしてgoquery:
package main
import (
"fmt"
"log"
"net/http"
"net/url"
"github.com/PuerkitoBio/goquery"
)
func main() {
proxyURL, _ := url.Parse("http://USERNAME:PASSWORD@gate.proxyhat.com:8080")
client := &http.Client{
Transport: &http.Transport{Proxy: http.ProxyURL(proxyURL)},
}
req, _ := http.NewRequest("GET", "https://www.google.com/search?q=best+residential+proxies&num=10&hl=en&gl=us", nil)
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36")
req.Header.Set("Accept-Language", "en-US,en;q=0.9")
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
doc, _ := goquery.NewDocumentFromReader(resp.Body)
doc.Find("div#search .g").Each(func(i int, s *goquery.Selection) {
title := s.Find("h3").Text()
link, _ := s.Find("a").Attr("href")
fmt.Printf("%d. %s\n %s\n\n", i+1, title, link)
})
}異なるSERPの特徴を解析
完全なスクレーパーは、単なる有機的な結果よりも処理する必要があります。 最も重要なSERP機能の解析パターンをご紹介します。
おすすめスニペット
# Python: Extract featured snippet
snippet_box = soup.select_one("div.xpdopen")
if snippet_box:
featured = {
"type": "featured_snippet",
"text": snippet_box.get_text(strip=True),
"source_url": snippet_box.select_one("a")["href"] if snippet_box.select_one("a") else None,
}人々はまた尋ねます
# Python: Extract PAA questions
paa_questions = []
for q in soup.select("div.related-question-pair"):
question_text = q.select_one("span")
if question_text:
paa_questions.append(question_text.get_text(strip=True))ローカルパック結果
# Python: Extract local pack
local_results = []
for item in soup.select("div.VkpGBb"):
name = item.select_one(".dbg0pd")
rating = item.select_one(".yi40Hd")
local_results.append({
"name": name.get_text() if name else "",
"rating": rating.get_text() if rating else "",
})GoogleブロックとCAPTCHAの処理
Googleは、自動スクレイピングに対して積極的に防御します。 適切なプロキシインフラがなければ、何十ものリクエストのブロックに遭遇します。 主防御機構は次のとおりです。
- レート制限: 1つのIPから多くのリクエストが429ステータスコードをトリガー
- CAPTCHAの課題: Googleは、自動化を疑ったときにreCAPTCHAを提供しています
- IPの評判: データセンター IP の範囲は、住宅 IP よりも多くのスクラッチを受け取ります
- ブラウザの指紋: 見つかりないヘッダーは旗を上げます
詳細な対策戦略については、ガイドをご覧ください ブロックせずにスクレイピング そして、 アンチボットシステムがプロキシを検出する方法. .
推奨プロキシ戦略
住宅用プロキシは、持続可能なGoogleスクレイピングに不可欠です。 ProxyHat住宅プロキシ 数百万人のIPへのアクセス 190+店舗IPを自動的に回転させ、リクエストをジオターゲットにすることができます。 主構成の先端:
- リクエストごとにIPを回転させる — Googleの連続クエリで同じIPを再利用しない
- リクエスト間で2-5秒間のランダムな遅延を追加
- ユーザーエージェントを実際のブラウザバージョンに合わせる
- セット
hlそして、glプロキシの場所と一貫性のあるパラメーター
参照して下さい ProxyHat ドキュメント 認証設定とセッション管理のため。
生産スクレーパーの構築
スクリプトから生産パイプラインへの移行には、再試行ロジック、構造化された出力、および監視が必要です。 Pythonスクレーパーの硬化バージョンは次のとおりです。
import requests
import time
import random
import json
from bs4 import BeautifulSoup
from datetime import datetime
PROXY_URL = "http://USERNAME:PASSWORD@gate.proxyhat.com:8080"
USER_AGENTS = [
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
]
def scrape_serp(query, location="us", retries=3):
for attempt in range(retries):
try:
headers = {
"User-Agent": random.choice(USER_AGENTS),
"Accept-Language": "en-US,en;q=0.9",
"Accept": "text/html,application/xhtml+xml",
}
response = requests.get(
"https://www.google.com/search",
params={"q": query, "num": 10, "hl": "en", "gl": location},
proxies={"http": PROXY_URL, "https": PROXY_URL},
headers=headers,
timeout=15,
)
if response.status_code == 429:
wait = (attempt + 1) * 10
print(f"Rate limited. Waiting {wait}s...")
time.sleep(wait)
continue
response.raise_for_status()
soup = BeautifulSoup(response.text, "html.parser")
# Check for CAPTCHA
if "captcha" in response.text.lower() or soup.select_one("#captcha-form"):
print(f"CAPTCHA detected. Retrying with new IP...")
time.sleep(random.uniform(5, 10))
continue
return parse_serp(soup, query)
except requests.RequestException as e:
print(f"Attempt {attempt + 1} failed: {e}")
time.sleep(random.uniform(2, 5))
return None
def parse_serp(soup, query):
results = {
"query": query,
"timestamp": datetime.utcnow().isoformat(),
"organic": [],
"featured_snippet": None,
"paa": [],
}
# Organic results
for i, g in enumerate(soup.select("div#search .g")):
title_el = g.select_one("h3")
link_el = g.select_one("a")
snippet_el = g.select_one(".VwiC3b")
if title_el and link_el:
results["organic"].append({
"position": i + 1,
"title": title_el.get_text(),
"url": link_el["href"],
"snippet": snippet_el.get_text() if snippet_el else "",
})
# Featured snippet
snippet_box = soup.select_one("div.xpdopen")
if snippet_box:
results["featured_snippet"] = snippet_box.get_text(strip=True)[:500]
# People Also Ask
for q in soup.select("div.related-question-pair span"):
results["paa"].append(q.get_text(strip=True))
return results
# Usage: scrape a list of keywords
keywords = ["best residential proxies", "proxy for web scraping", "serp tracking tools"]
all_results = []
for kw in keywords:
result = scrape_serp(kw)
if result:
all_results.append(result)
time.sleep(random.uniform(3, 7)) # Delay between keywords
# Save to JSON
with open("serp_results.json", "w") as f:
json.dump(all_results, f, indent=2)SERPスクレーパーのスケーリング
数百または数千のキーワードを監視すると、読み込まれたスクレイピングが遅くなります。 これらのスケーリングアプローチを考慮する:
- 同時リクエスト: asyncio (Python), ワーカースレッド (Node.js), または goroutines (Go) を使用して、複数のリクエストを並列に送信する
- Queue ベースのアーキテクチャ: キーワードをキュー (Redis, RabbitMQ) にプッシュし、複数のワーカーで処理
- プロキシプール管理: ProxyHat は、自動で回転を処理しますが、ニーズに基づいてセッションの粘度を設定できます。
- 結果キャッシュ: SERPデータをキャッシュし、時間ウィンドウ内の同じクエリの冗長リクエストを回避
スケーラブルスクレーピングシステムの構築に関する包括的なガイダンスについては、 ウェブスクレイピングプロキシの完全なガイド. .
法的および倫理的考慮事項
Googleの利用規約は自動アクセスを制限します。 Google SERPをスクラップするときは、次のガイドラインに従ってください。
- レート制限を尊重し、圧倒的なGoogleのサーバーを回避
- 正当な事業目的のためにデータを使用する(SEO監視、市場調査)
- 適用される法律を理解しずに、原材料のSERPデータを商業的に再配布しないでください
- ニーズに合ったGoogleの公式APIを利用しましょう
SERPスクレーパーをスケールで展開する前に、Webスクレイピングやデータ収集に関する現地の法律を常にチェックします。






