fixed brave news
This commit is contained in:
		
							parent
							
								
									165d80f80b
								
							
						
					
					
						commit
						9fd993b47b
					
				| @ -1139,131 +1139,54 @@ class brave{ | ||||
| 				$proxy | ||||
| 			); | ||||
| 		 | ||||
| 		$news = | ||||
| 			$this->fuckhtml | ||||
| 			->getElementsByClassName( | ||||
| 				"snippet inline gap-standard", | ||||
| 				"div" | ||||
| 		preg_match( | ||||
| 			'/const data ?= ?(\[{.*}]);/', | ||||
| 			$html, | ||||
| 			$json | ||||
| 		); | ||||
| 		 | ||||
| 		foreach($news as $article){ | ||||
| 		if(!isset($json[1])){ | ||||
| 			 | ||||
| 			$data = [ | ||||
| 				"title" => null, | ||||
| 				"author" => null, | ||||
| 				"description" => null, | ||||
| 				"date" => null, | ||||
| 				"thumb" => | ||||
| 					[ | ||||
| 						"url" => null, | ||||
| 						"ratio" => null | ||||
| 					], | ||||
| 				"url" => null | ||||
| 			]; | ||||
| 			 | ||||
| 			$this->fuckhtml->load($article); | ||||
| 			$elems = | ||||
| 				$this->fuckhtml | ||||
| 				->getElementsByTagName("*"); | ||||
| 			 | ||||
| 			// get title
 | ||||
| 			$data["title"] = | ||||
| 				$this->fuckhtml | ||||
| 				->getTextContent( | ||||
| 					$this->fuckhtml | ||||
| 					->getElementsByClassName( | ||||
| 						"snippet-title", | ||||
| 						$elems | ||||
| 					) | ||||
| 					[0] | ||||
| 					["innerHTML"] | ||||
| 				); | ||||
| 			 | ||||
| 			// get description
 | ||||
| 			$data["description"] = | ||||
| 				$this->titledots( | ||||
| 					$this->fuckhtml | ||||
| 					->getTextContent( | ||||
| 						$this->fuckhtml | ||||
| 						->getElementsByClassName( | ||||
| 							"snippet-description", | ||||
| 							$elems | ||||
| 						) | ||||
| 						[0] | ||||
| 						["innerHTML"] | ||||
| 					) | ||||
| 				); | ||||
| 			 | ||||
| 			// get date
 | ||||
| 			$date = | ||||
| 				explode( | ||||
| 					"•", | ||||
| 					$this->fuckhtml | ||||
| 					->getTextContent( | ||||
| 						$this->fuckhtml | ||||
| 						->getElementsByClassName( | ||||
| 							"snippet-url", | ||||
| 							$elems | ||||
| 						)[0] | ||||
| 					) | ||||
| 				); | ||||
| 			 | ||||
| 			if( | ||||
| 				count($date) !== 1 && | ||||
| 				trim($date[1]) != "" | ||||
| 			){ | ||||
| 				 | ||||
| 				$data["date"] = | ||||
| 					strtotime( | ||||
| 						$date[1] | ||||
| 					); | ||||
| 			throw new Exception("Failed to grep javascript object"); | ||||
| 		} | ||||
| 		 | ||||
| 			// get URL
 | ||||
| 			$data["url"] = | ||||
| 				$this->fuckhtml->getTextContent( | ||||
| 					$this->unshiturl( | ||||
| 						$this->fuckhtml | ||||
| 						->getElementsByClassName( | ||||
| 							"result-header", | ||||
| 							$elems | ||||
| 						) | ||||
| 						[0] | ||||
| 						["attributes"] | ||||
| 						["href"] | ||||
| 					) | ||||
| 				); | ||||
| 		$json = $this->fuckhtml->parseJsObject($json[1], true); | ||||
| 		 | ||||
| 			// get thumbnail
 | ||||
| 			$thumb = | ||||
| 				$this->fuckhtml | ||||
| 				->getElementsByTagName( | ||||
| 					"img" | ||||
| 				); | ||||
| 		if($json === null){ | ||||
| 			 | ||||
| 			if( | ||||
| 				count($thumb) === 2 && | ||||
| 				trim( | ||||
| 					$thumb[1] | ||||
| 					["attributes"] | ||||
| 					["src"] | ||||
| 				) != "" | ||||
| 			throw new Exception("Failed to parse javascript object"); | ||||
| 		} | ||||
| 		 | ||||
| 		foreach( | ||||
| 			$json[1]["data"]["body"]["response"]["news"]["results"] | ||||
| 			as $news | ||||
| 		){ | ||||
| 			 | ||||
| 				$data["thumb"] = [ | ||||
| 					"url" => | ||||
| 						$this->fuckhtml->getTextContent( | ||||
| 							$this->unshiturl( | ||||
| 								$thumb[1] | ||||
| 								["attributes"] | ||||
| 								["src"] | ||||
| 							) | ||||
| 						), | ||||
| 			if( | ||||
| 				!isset($news["thumbnail"]["src"]) || | ||||
| 				$news["thumbnail"]["src"] == "void 0" | ||||
| 			){ | ||||
| 								 | ||||
| 				$thumb = [ | ||||
| 					"url" => null, | ||||
| 					"ratio" => null | ||||
| 				]; | ||||
| 			}else{ | ||||
| 								 | ||||
| 				$thumb = [ | ||||
| 					"url" => $this->unshiturl($news["thumbnail"]["src"]), | ||||
| 					"ratio" => "16:9" | ||||
| 				]; | ||||
| 			} | ||||
| 			 | ||||
| 			$out["news"][] = $data; | ||||
| 			$out["news"][] = [ | ||||
| 				"title" => $news["title"], | ||||
| 				"author" => null, | ||||
| 				"description" => $news["description"], | ||||
| 				"date" => !isset($news["age"]) || $news["age"] == "void 0" ? null : strtotime($news["age"]), | ||||
| 				"thumb" => $thumb, | ||||
| 				"url" => $news["url"] | ||||
| 			]; | ||||
| 		} | ||||
| 		 | ||||
| 		return $out; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 lolcat
						lolcat