From 640d1d1953669115dc67dfdaf86998401a9bfac4 Mon Sep 17 00:00:00 2001 From: lolcat Date: Mon, 24 Jun 2024 17:15:54 -0400 Subject: fixed nasty brave bug --- scraper/brave.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'scraper') diff --git a/scraper/brave.php b/scraper/brave.php index 8be55ac..3e6c449 100644 --- a/scraper/brave.php +++ b/scraper/brave.php @@ -295,6 +295,7 @@ class brave{ $html = fread($handle, filesize("scraper/brave.html")); fclose($handle); */ + try{ $html = $this->get( @@ -406,9 +407,9 @@ class brave{ if(!isset($grep[1])){ - throw new Exception("Could not get data JS"); + throw new Exception("Could not grep JavaScript object"); } - + $data = $this->fuckhtml ->parseJsObject( @@ -416,6 +417,11 @@ class brave{ ); unset($grep); + if($data === null){ + + throw new Exception("Failed to decode JavaScript object"); + } + $data = $data[1]["data"]["body"]["response"]; /* -- cgit v1.2.3 From 77931f3ee9b2a51d83b05752b3d98638b30cae38 Mon Sep 17 00:00:00 2001 From: lolcat Date: Tue, 25 Jun 2024 18:05:43 -0400 Subject: brave error handling --- scraper/brave.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'scraper') diff --git a/scraper/brave.php b/scraper/brave.php index 3e6c449..fd4c46e 100644 --- a/scraper/brave.php +++ b/scraper/brave.php @@ -422,6 +422,19 @@ class brave{ throw new Exception("Failed to decode JavaScript object"); } + if( + isset($data[2]["data"]["title"]) && + stripos($data[2]["data"]["title"], "PoW Captcha") !== false + ){ + + throw new Exception("Brave returned a PoW captcha"); + } + + if(!isset($data[1]["data"]["body"]["response"])){ + + throw new Exception("Brave did not return a result object"); + } + $data = $data[1]["data"]["body"]["response"]; /* -- cgit v1.2.3