建立一个准确的请求指纹
描述查询,Google域名,编码位置,界面语言,国家,设备,表面和工作流所需的结果窗口.
From query to usable objects
描述查询,Google域名,编码位置,界面语言,国家,设备,表面和工作流所需的结果窗口.
阅读记录的元数据和结果阵列,而不是将应用程序连接到搜索页面的表达标记.
根据请求背景和Google的表面,它们的存在会有所不同.
在计算位置,变化,出版商覆盖范围或特定产品信号之前,将请求文本放在结果旁边.
在时间推移之前,将此指纹与解析的反应存储起来,
文件的谷歌表面
常规的网页结果使用谷歌引擎,没有垂直选择器. 文件控制扩展到媒体,商业和工作面的相同请求模型.
发送 engine=google 及所需的 q 离开 tbm 对于常规的谷歌搜索结果未设置.
设置记录的垂直选择器为 tbm=isch.
设置记录的垂直选择器为 tbm=vid.
设置记录的垂直选择器为子.
设置记录的垂直选择器为果.
使用记录的职位值 ibp=htl;jobs.
请求参数
开始使用所需查询参数. 添加文件可选控制,只需要工作流需要特定的表面,演示,局域或结果窗口.
q在谷歌搜索的关键字.
需要的字符串tbm ibptbm 选择记录的图像,视频,新闻或购物垂直. ibp 支持记录的求职值.
device选择支持桌面,手机或平板电脑搜索演示.
字符串 · 选择性domain选择用于搜索的谷歌域名.
字符串 · 选择性uule通过Google编码的位置为搜索文本.
字符串 · 选择性hl glhl 设置接口语言; gl 提供用于本地搜索的国家代码.
start numstart 是结果被抵消过错; num 要求每个页面的结果数量.
分析谷歌的响应
记录的响应包含搜索元数据和解析的JSON结果集合.在特定响应中存在的块取决于查询,本地,设备和搜索垂直.
01 · 环境
general搜索引擎,结果数量,语言,位置,演示,搜索类型,页面标题和时间标签,以记录的响应示例显示.
02 · 要求追踪
input要求信息,如在记录响应示例中显示的原始URL和用户代理字段.
03 ·发现路径
navigation返回导航输入可以识别查询的其他谷歌搜索面.
04 · 分析结果
organic[]记录的有机物体包括链接,显示链接,标题,描述,排名和返回时的全球排名等领域.
一个文本要求
选择查询,搜索面,谷歌域名,编码位置,语言,国家,设备和页面窗口,该决定要求.
发送一个GET请求给 https://serpapi.webscrapingapi.com/v2 with api_key, engine=google ,以及 q.
检查HTTP结果,解析JSON,阅读您的工作流需要的集合,并保存存储的结果的请求文本.
整合
保持API键在服务器侧配置中,编码查询值,设置明确的时间限,并在解析响应之前表现出未成功的HTTP结果.
: "${WSA_API_KEY:?WSA_API_KEY is required}"
curl --get --fail-with-body --max-time 120 \
"https://serpapi.webscrapingapi.com/v2" \
--data-urlencode "api_key=$WSA_API_KEY" \
--data-urlencode "engine=google" \
--data-urlencode "q=best trail shoes" \
--data-urlencode "gl=us" \
--data-urlencode "hl=en" \
--data-urlencode "device=mobile"const apiKey = process.env.WSA_API_KEY;
if (!apiKey) throw new Error("WSA_API_KEY is required");
const parameters = new URLSearchParams({
"api_key": apiKey,
"engine": "google",
"q": "best trail shoes",
"gl": "us",
"hl": "en",
"device": "mobile",
});
const response = await fetch(
"https://serpapi.webscrapingapi.com/v2?" + parameters,
{ signal: AbortSignal.timeout(120_000) }
);
if (!response.ok) {
throw new Error("Google Search API status " + response.status);
}
console.log(await response.json());import os
import requests
api_key = os.environ.get("WSA_API_KEY")
if not api_key:
raise RuntimeError("WSA_API_KEY is required")
response = requests.get(
"https://serpapi.webscrapingapi.com/v2",
params={
"api_key": api_key,
"engine": "google",
"q": "best trail shoes",
"gl": "us",
"hl": "en",
"device": "mobile",
},
timeout=120,
)
response.raise_for_status()
print(response.json())<?php
$apiKey = getenv("WSA_API_KEY");
if ($apiKey === false || $apiKey === "") {
throw new RuntimeException("WSA_API_KEY is required");
}
$endpoint = "https://serpapi.webscrapingapi.com/v2"
. "?engine=google"
. "&api_key=" . rawurlencode($apiKey)
. "&q=" . rawurlencode("best trail shoes")
. "&gl=us&hl=en&device=mobile";
$client = curl_init($endpoint);
curl_setopt_array($client, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 120,
]);
$body = curl_exec($client);
$status = curl_getinfo($client, CURLINFO_RESPONSE_CODE);
$error = curl_error($client);
curl_close($client);
if ($body === false) throw new RuntimeException($error);
if ($status >= 400) throw new RuntimeException("API status " . $status);
echo $body;package main
import (
"fmt"
"io"
"net/http"
"net/url"
"os"
"time"
)
func main() {
apiKey := os.Getenv("WSA_API_KEY")
if apiKey == "" { panic("WSA_API_KEY is required") }
endpoint := "https://serpapi.webscrapingapi.com/v2?engine=google" +
"&api_key=" + url.QueryEscape(apiKey) +
"&q=" + url.QueryEscape("best trail shoes") +
"&gl=us&hl=en&device=mobile"
client := &http.Client{Timeout: 120 * time.Second}
response, err := client.Get(endpoint)
if err != nil { panic(err) }
defer response.Body.Close()
if response.StatusCode >= 400 {
panic(fmt.Sprintf("API status %d", response.StatusCode))
}
body, err := io.ReadAll(response.Body)
if err != nil { panic(err) }
fmt.Println(string(body))
}import java.net.URI;
import java.net.URLEncoder;
import java.net.http.*;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
public final class GoogleSearchApiExample {
public static void main(String[] args) throws Exception {
String apiKey = System.getenv("WSA_API_KEY");
if (apiKey == null || apiKey.isBlank()) {
throw new IllegalStateException("WSA_API_KEY is required");
}
String endpoint = "https://serpapi.webscrapingapi.com/v2"
+ "?engine=google"
+ "&api_key=" + URLEncoder.encode(
apiKey, StandardCharsets.UTF_8)
+ "&q=" + URLEncoder.encode(
"best trail shoes", StandardCharsets.UTF_8)
+ "&gl=us&hl=en&device=mobile";
var request = HttpRequest.newBuilder(URI.create(endpoint))
.timeout(Duration.ofSeconds(120))
.GET().build();
var response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() < 200 || response.statusCode() >= 300) {
throw new RuntimeException("API status " + response.statusCode());
}
System.out.println(response.body());
}
}
using System;
using System.Net;
using System.Net.Http;
var rawApiKey = Environment.GetEnvironmentVariable("WSA_API_KEY");
if (string.IsNullOrWhiteSpace(rawApiKey)) {
throw new InvalidOperationException("WSA_API_KEY is required");
}
var apiKey = WebUtility.UrlEncode(rawApiKey);
var query = WebUtility.UrlEncode("best trail shoes");
var endpoint = "https://serpapi.webscrapingapi.com/v2"
+ "?engine=google&api_key=" + apiKey
+ "&q=" + query
+ "&gl=us&hl=en&device=mobile";
using var client = new HttpClient();
client.Timeout = TimeSpan.FromSeconds(120);
var response = await client.GetAsync(endpoint);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());require "net/http"
require "uri"
api_key = ENV["WSA_API_KEY"]
raise "WSA_API_KEY is required" if api_key.nil? || api_key.empty?
api_key = URI.encode_www_form_component(api_key)
query = URI.encode_www_form_component("best trail shoes")
uri = URI("https://serpapi.webscrapingapi.com/v2" +
"?engine=google&api_key=#{api_key}&q=#{query}" +
"&gl=us&hl=en&device=mobile")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.open_timeout = 10
http.read_timeout = 120
response = http.get(uri.request_uri)
unless response.is_a?(Net::HTTPSuccess)
raise "API status #{response.code}"
end
puts response.bodyhttps://serpapi.webscrapingapi.com/v2
api_key + engine=google + q
gl=us + hl=en + device=mobile
120秒客户端时间停止和明确的HTTP错误处理
买家工作流程
产品选择
产量评估
现在的价格和计划条件仍然是商业的真相来源.
FAQ
谷歌搜索API返回请求文本和解析的JSON结果集合.有机结果被记录,而导航和其他响应模块取决于查询,本地,设备和请求搜索表面.
需要的查询使用q. 文件可选控制包括 tbm,ibp,设备,域名,uule,hl,gl,start和num用于搜索表面,演示,本地化和页面化.
让 tbm 不设置用于常规的网页搜索,或使用记录的 tbm值用于图像,视频,新闻和购物. 乔布斯使用记录的 ibp 控制. 验证返回的形状为您的应用需要的表面.
没有.谷歌结果模块根据查询,本地,设备和搜索垂直变化. 处理响应区块是可选的,区分一个缺失的集合和一个失败的HTTP请求,只阅读您的应用程序需要的模块.
在您的工作流程提交谷歌搜索时,使用分别记录的 google_async 引擎,并通过Snapshot API 检索完成的 SERP 实用载荷.
保存 api_key 在服务器端环境变量中,编码URL查询值,设置明确的时间限,并在解析 JSON之前检查HTTP状态.