Kaynağa Gözat

handle failed redirect fetches

lolcat 1 hafta önce
ebeveyn
işleme
42d0252e2f
1 değiştirilmiş dosya ile 20 ekleme ve 11 silme
  1. 20 11
      scraper/google.php

+ 20 - 11
scraper/google.php

@@ -706,20 +706,29 @@ class google{
 			
 			if(count($a) === 0){
 				
-				throw new Exception("Failed to find link");
+				// failed to find link, will serve a resolver target as fallback
+				$fallback = true;
+				$slug = explode("url=", $this->handles[$i]["replacement"]);
+				$link = "/resolver?scraper=google&target=" . rawurlencode($slug[1]);
+			}else{
+				
+				$fallback = false;
+				$link =
+					$this->fuckhtml
+					->getTextContent(
+						$a[0]["attributes"]["href"]
+					);
 			}
 			
-			$link =
-				$this->fuckhtml
-				->getTextContent(
-					$a[0]["attributes"]["href"]
-				);
-			
 			if(
-				preg_match(
-					'/^(https?:|)\/\//',
-					$link
-				)
+				(
+					$fallback === false &&
+					preg_match(
+						'/^(https?:|)\/\//',
+						$link
+					)
+				) ||
+				$fallback === true
 			){
 				
 				$keys[] = $this->handles[$i]["replacement"];