parent
21c1c1e619
commit
d6159f66fb
2 changed files with 31 additions and 123 deletions
|
|
@ -666,14 +666,24 @@ class baidu{
|
|||
//
|
||||
// Don't parse as a search result if it's a card
|
||||
//
|
||||
$card =
|
||||
$tpl_probe =
|
||||
$this->fuckhtml
|
||||
->getElementsByClassName(
|
||||
"cosc-card",
|
||||
$div
|
||||
->getElementsByAttributeValue(
|
||||
"tpl",
|
||||
"www_index",
|
||||
[$datafield]
|
||||
);
|
||||
|
||||
if(count($card) !== 0){
|
||||
if(
|
||||
count($tpl_probe) === 0 &&
|
||||
count(
|
||||
$this->fuckhtml
|
||||
->getElementsByClassName(
|
||||
"cosc-card",
|
||||
$div
|
||||
)
|
||||
) !== 0
|
||||
){
|
||||
|
||||
//
|
||||
// Parse chinese youtube shorts
|
||||
|
|
@ -870,10 +880,13 @@ class baidu{
|
|||
// class:FYB_RD -> News garbage, IGNORE
|
||||
|
||||
$result =
|
||||
$this->fuckhtml
|
||||
->getElementsByClassName(
|
||||
"result",
|
||||
[$datafield]
|
||||
array_merge(
|
||||
$tpl_probe,
|
||||
$this->fuckhtml
|
||||
->getElementsByClassName(
|
||||
"result",
|
||||
[$datafield]
|
||||
)
|
||||
);
|
||||
|
||||
if(count($result) !== 0){
|
||||
|
|
@ -885,7 +898,7 @@ class baidu{
|
|||
$title =
|
||||
$this->fuckhtml
|
||||
->getElementsByClassName(
|
||||
"sc-link",
|
||||
"cosc-title-a",
|
||||
"a"
|
||||
);
|
||||
|
||||
|
|
@ -905,8 +918,9 @@ class baidu{
|
|||
|
||||
$description =
|
||||
$this->fuckhtml
|
||||
->getElementsByClassName(
|
||||
"c-color",
|
||||
->getElementsByAttributeValue(
|
||||
"data-sanssr-cmpt",
|
||||
"card/www-summary-1",
|
||||
$div
|
||||
);
|
||||
|
||||
|
|
@ -2051,7 +2065,7 @@ class baidu{
|
|||
$parts = explode("src=", $url);
|
||||
if(count($parts) !== 2){
|
||||
|
||||
// stuff
|
||||
// stuff is broken
|
||||
return $url;
|
||||
}
|
||||
|
||||
|
|
@ -2062,11 +2076,11 @@ class baidu{
|
|||
|
||||
if(count($q) !== 2){
|
||||
|
||||
// stuff
|
||||
// stuff is broken, again
|
||||
return $url;
|
||||
}
|
||||
|
||||
// baidu devs are fucking retarded and dont follow spec:
|
||||
// baidu devs are not following specs:
|
||||
// &fmt=auto?s=BB32F3A050471AEC72886934030090C4&sec=1753203600&t=0fb2194775d3bd3d1bb114b818479e0a
|
||||
parse_str(str_replace("?", "&", $q[1]), $query);
|
||||
|
||||
|
|
|
|||
110
scraper/ddg.php
110
scraper/ddg.php
|
|
@ -54,8 +54,8 @@ class ddg{
|
|||
$headers =
|
||||
["User-Agent: " . config::USER_AGENT,
|
||||
"Accept: */*",
|
||||
"Accept-Language: en-US,en;q=0.5",
|
||||
"Accept-Encoding: gzip",
|
||||
"Accept-Language: en-US,en;q=0.9",
|
||||
"Accept-Encoding: gzip, deflate, br, zstd",
|
||||
"Referer: https://duckduckgo.com/",
|
||||
"DNT: 1",
|
||||
"Sec-GPC: 1",
|
||||
|
|
@ -920,112 +920,6 @@ class ddg{
|
|||
){
|
||||
|
||||
throw new Exception("DuckDuckGo returned a JSA challenge");
|
||||
|
||||
// get JSA initial token
|
||||
if(
|
||||
!preg_match(
|
||||
'/let jsa *= *([0-9]+)/',
|
||||
$js,
|
||||
$jsa
|
||||
)
|
||||
){
|
||||
|
||||
$jsa = 0;
|
||||
}else{
|
||||
|
||||
$jsa = (int)$jsa[1];
|
||||
}
|
||||
|
||||
// get function bodies
|
||||
preg_match_all(
|
||||
'/let *([A-Za-z0-9]+) *= *function\(.*\) *{(.*)};/sU',
|
||||
$js,
|
||||
$functions
|
||||
);
|
||||
|
||||
$parsed_functions = [];
|
||||
|
||||
for($i=0; $i<count($functions[0]); $i++){
|
||||
|
||||
$functions[2][$i] = trim($functions[2][$i]);
|
||||
|
||||
if(
|
||||
preg_match(
|
||||
'/return num *\* *([0-9]+)/i',
|
||||
$functions[2][$i],
|
||||
$num
|
||||
)
|
||||
){
|
||||
|
||||
$parsed_functions[$functions[1][$i]] = [
|
||||
"type" => "multiplication",
|
||||
"num" => (int)$num[1]
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
if(
|
||||
preg_match(
|
||||
'/innerHTML *= *`([^`]+)`/i',
|
||||
$functions[2][$i],
|
||||
$challenge
|
||||
)
|
||||
){
|
||||
|
||||
$challenge[1] =
|
||||
preg_replace(
|
||||
'/<\/(br)>/',
|
||||
'<$1>',
|
||||
$challenge[1]
|
||||
);
|
||||
|
||||
$parsed_functions[$functions[1][$i]] = [
|
||||
"type" => "challenge",
|
||||
"text" => $challenge[1]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// get function call order
|
||||
preg_match_all(
|
||||
'/jsa *= *([A-Za-z0-9]+)\(jsa\)/i',
|
||||
$js,
|
||||
$call_order
|
||||
);
|
||||
|
||||
foreach($call_order[1] as $order){
|
||||
|
||||
if(!isset($parsed_functions[$order])){
|
||||
|
||||
throw new Exception("JS challenge solve failure: DuckDuckGo called an unknown function");
|
||||
}
|
||||
|
||||
if($parsed_functions[$order]["type"] == "multiplication"){
|
||||
|
||||
$jsa = $jsa * $parsed_functions[$order]["num"];
|
||||
continue;
|
||||
}
|
||||
|
||||
if($parsed_functions[$order]["type"] == "challenge"){
|
||||
|
||||
// @TODO get parsed length
|
||||
//$parsed_functions[$order]["text"]
|
||||
|
||||
$jsa = $jsa + strlen($parsed_functions[$order]["text"]);
|
||||
}
|
||||
}
|
||||
|
||||
try{
|
||||
$js = $this->get(
|
||||
$proxy,
|
||||
"https://links.duckduckgo.com" . $challenge_url[1] . $jsa,
|
||||
[],
|
||||
ddg::req_xhr
|
||||
);
|
||||
}catch(Exception $error){
|
||||
|
||||
throw new Exception("Failed to get challenged d.js");
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
|||
Loading…
Reference in a new issue