Преглед на файлове

qwant gibberish check fix

lolcat преди 2 години
родител
ревизия
b492ef2329
променени са 1 файла, в които са добавени 12 реда и са изтрити 12 реда
  1. 12 12
      scraper/qwant.php

+ 12 - 12
scraper/qwant.php

@@ -360,7 +360,17 @@ class qwant{
 				return $out;
 			}
 			
-			throw new Exception("Server returned an error code: " . $json["data"]["error_code"]);
+			if(isset($json["data"]["error_code"])){
+				
+				switch($json["data"]["error_code"]){
+					
+					case 27:
+						throw new Exception("Qwant returned a captcha");
+						break;
+				}
+			}
+			
+			throw new Exception("Qwant returned an error code: " . $json["data"]["error_code"]);
 		}
 		
 		if(!isset($json["data"]["result"]["items"]["mainline"])){
@@ -488,17 +498,7 @@ class qwant{
 						// detect gibberish results
 						if(
 							$first_iteration &&
-							preg_match(
-								"/^" .
-								preg_quote(
-									$this->trimdots(
-										$result["source"]
-									),
-									"/"
-								) .
-								"/",
-								$result["url"]
-							) !== 1
+							!isset($result["urlPingSuffix"])
 						){
 							
 							throw new Exception("Qwant returned gibberish results");