aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--scraper/google_cse.php19
1 files changed, 14 insertions, 5 deletions
diff --git a/scraper/google_cse.php b/scraper/google_cse.php
index 02ab462..8576f96 100644
--- a/scraper/google_cse.php
+++ b/scraper/google_cse.php
@@ -910,11 +910,10 @@ class google_cse{
"image" => []
];
- // detect next page
- if(
- isset($json["cursor"]["isExactTotalResults"]) || // detects last page
- !isset($json["cursor"]["pages"]) // detects no results on page
- ){
+ // A response can contain a final page of image results while also marking
+ // the cursor as exact/finished. Parse those results before deciding
+ // whether another page token should be offered.
+ if(!isset($json["results"]) || !is_array($json["results"])){
return $out;
}
@@ -939,6 +938,16 @@ class google_cse{
];
}
+ // Only decide whether a following page exists after preserving every
+ // result returned on this page.
+ if(
+ isset($json["cursor"]["isExactTotalResults"]) || // detects last page
+ !isset($json["cursor"]["pages"]) // detects no results on page
+ ){
+
+ return $out;
+ }
+
// get next page
$out["npt"] =
$this->backend->store(
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage