handle cucked urls on google
This commit is contained in:
1 parent
36b1deb485
commit
0e5258a1b9
1 file changed
+91
-26
+91
-26
@@ -891,7 +891,7 @@ class google{
|
|||||||
$html = &$data["data"];
|
$html = &$data["data"];
|
||||||
$container = &$data["container"];
|
$container = &$data["container"];
|
||||||
//file_put_contents("scraper/google-jp.html", $html);
|
//file_put_contents("scraper/google-jp.html", $html);
|
||||||
//$html = file_get_contents("scraper/google.html");
|
//$html = file_get_contents("scraper/doc1.html");
|
||||||
//$container = "";
|
//$container = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1263,8 +1263,36 @@ class google{
|
|||||||
$this->fuckhtml
|
$this->fuckhtml
|
||||||
->getElementsByTagName("cite");
|
->getElementsByTagName("cite");
|
||||||
|
|
||||||
|
$cuckurl = null;
|
||||||
|
|
||||||
if(isset($cite[0])){
|
if(isset($cite[0])){
|
||||||
|
|
||||||
|
//
|
||||||
|
// get cucked URL
|
||||||
|
//
|
||||||
|
$cite_conv =
|
||||||
|
$this->fuckhtml
|
||||||
|
->getTextContent(
|
||||||
|
$cite[0]
|
||||||
|
);
|
||||||
|
|
||||||
|
// is it a cucked URL?
|
||||||
|
if(
|
||||||
|
preg_match(
|
||||||
|
'/^http/',
|
||||||
|
$cite_conv
|
||||||
|
) !== 0
|
||||||
|
){
|
||||||
|
|
||||||
|
// https://www.sleepfoundation.org › ... › ASMR for Sleep
|
||||||
|
$cuckurl =
|
||||||
|
preg_replace(
|
||||||
|
'/ *› */',
|
||||||
|
"/",
|
||||||
|
$cite_conv
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$texts =
|
$texts =
|
||||||
explode(
|
explode(
|
||||||
" · ",
|
" · ",
|
||||||
@@ -1298,12 +1326,72 @@ class google{
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// anything else?
|
// table elements
|
||||||
$table[ucfirst($probe[2])] = trim($probe[1]);
|
$table[ucfirst($probe[2])] = trim($probe[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($cuckurl === null){
|
||||||
|
|
||||||
|
// failed to get a valid URL
|
||||||
|
// lets create some make believe URL
|
||||||
|
|
||||||
|
$website_name =
|
||||||
|
$this->fuckhtml
|
||||||
|
->getElementsByClassName(
|
||||||
|
$this->getstyle([
|
||||||
|
"color" => "var(" . $this->getcolorvar("#16171a") . ")",
|
||||||
|
"font-size" => "var(--zng88)",
|
||||||
|
"display" => "block",
|
||||||
|
"line-height" => "20px",
|
||||||
|
"white-space" => "nowrap",
|
||||||
|
"overflow-x" => "hidden",
|
||||||
|
"text-overflow" => "ellipsis",
|
||||||
|
"width" => "auto",
|
||||||
|
"font-family" => "google sans,sans-serif"
|
||||||
|
]),
|
||||||
|
"span"
|
||||||
|
);
|
||||||
|
|
||||||
|
if(count($website_name) !== 0){
|
||||||
|
|
||||||
|
$website_name =
|
||||||
|
html_entity_decode(
|
||||||
|
$website_name[0]["innerHTML"]
|
||||||
|
);
|
||||||
|
|
||||||
|
$website_name = explode("·", $website_name, 2);
|
||||||
|
|
||||||
|
// replacing spaces should take care of "stack overflow"
|
||||||
|
$website_domain =
|
||||||
|
str_replace(
|
||||||
|
" ",
|
||||||
|
"",
|
||||||
|
trim(
|
||||||
|
strtolower(
|
||||||
|
$website_name[0]
|
||||||
|
),
|
||||||
|
" \t\n\r\0\x0B\xC2\xA0"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// @todo find more TLDs, but i think theres just twitch thats weird
|
||||||
|
switch($website_domain){
|
||||||
|
|
||||||
|
case "twitch": $website_domain = "twitch.tv"; break;
|
||||||
|
default: $website_domain = "{$website_domain}.com";
|
||||||
|
}
|
||||||
|
|
||||||
|
$cuckurl = "https://" . $website_domain;
|
||||||
|
|
||||||
|
if(isset($website_name[1])){
|
||||||
|
|
||||||
|
$cuckurl .= "/" . trim($website_name[1], " \t\n\r\0\x0B\xC2\xA0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// get description/image wrapper
|
// get description/image wrapper
|
||||||
$desc_img_wrappers =
|
$desc_img_wrappers =
|
||||||
$this->fuckhtml
|
$this->fuckhtml
|
||||||
@@ -1374,30 +1462,6 @@ class google{
|
|||||||
|
|
||||||
$t = trim(html_entity_decode($t));
|
$t = trim(html_entity_decode($t));
|
||||||
|
|
||||||
if(preg_match("/\p{Sc}/u", $t)){
|
|
||||||
|
|
||||||
$table["Price"] = $t;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(str_contains($t, "stock")){
|
|
||||||
|
|
||||||
$table["Stock"] = $t;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(str_contains($t, "return")){
|
|
||||||
|
|
||||||
$table["Returns"] = $t;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(str_contains($t, "delivery")){
|
|
||||||
|
|
||||||
$table["Delivery"] = $t;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 5.0(590,004)
|
// 5.0(590,004)
|
||||||
if(preg_match('/^([0-9kmb\/%.,]+) *(\([0-9kmb,.]+\))?/', $t, $match)){
|
if(preg_match('/^([0-9kmb\/%.,]+) *(\([0-9kmb,.]+\))?/', $t, $match)){
|
||||||
|
|
||||||
@@ -1475,6 +1539,7 @@ class google{
|
|||||||
"title" => $title,
|
"title" => $title,
|
||||||
"description" => $description,
|
"description" => $description,
|
||||||
"url" => $this->convert_goto_to_resolver($url),
|
"url" => $this->convert_goto_to_resolver($url),
|
||||||
|
"cuckurl" => $cuckurl,
|
||||||
"date" => $date,
|
"date" => $date,
|
||||||
"type" => "web",
|
"type" => "web",
|
||||||
"thumb" => $thumb,
|
"thumb" => $thumb,
|
||||||
|
|||||||
Reference in new issue
Block a user