Google प्रति पेज ~10 ऑर्गेनिक नतीजे लौटाता है। 100 तक जमा करने के लिए, आप page पैरामीटर के साथ नतीजों में पेज-दर-पेज जाते हैं। यहाँ serp.cheap के साथ इसे कुशलता से करने का तरीका है।
मूल बातें
page1-इंडेक्स्ड है (1= पहला पेज)।- हर पेज ~10 ऑर्गेनिक नतीजे लौटाता है।
- हर पेज एक अलग बिल वाली रिक्वेस्ट है — तो 100 नतीजे ≈ 10 रिक्वेस्ट।
Python: 100 तक नतीजे जमा करें
import requests
def fetch_results(q, gl="us", max_results=100):
out, page = [], 1
while len(out) < max_results:
r = requests.post(
"https://api.serp.cheap/v1/search",
headers={"X-API-Key": "YOUR_KEY"},
json={"q": q, "gl": gl, "page": page},
timeout=30,
)
r.raise_for_status()
batch = r.json()["organic"]
if not batch:
break # no more results
out += batch
page += 1
return out[:max_results]
results = fetch_results("best project management software")
print(len(results), "results")
Node.js
async function fetchResults(q, max = 100) {
const out = [];
for (let page = 1; out.length < max; page++) {
const res = await fetch("https://api.serp.cheap/v1/search", {
method: "POST",
headers: { "X-API-Key": process.env.SERP_KEY, "Content-Type": "application/json" },
body: JSON.stringify({ q, gl: "us", page }),
});
const { organic } = await res.json();
if (!organic.length) break;
out.push(...organic);
}
return out.slice(0, max);
}
टिप्स
- अगर आप पेज मिलाते हैं तो link से डुप्लिकेट हटाएँ — कभी-कभार ओवरलैप हो सकता है।
- जब कोई पेज कोई नतीजा न लौटाए तो जल्दी रुक जाएँ।
- आलस से लाएँ — अगर आप सिर्फ़ 10 दिखाते हैं तो 100 नतीजे न खींचें। खर्च पेजों के साथ बढ़ता है।