hyung..sunbae.. i fixed naver
This commit is contained in:
+73
-22
@@ -261,9 +261,10 @@ class naver{
|
|||||||
|
|
||||||
$filters = [
|
$filters = [
|
||||||
"nso" => "",
|
"nso" => "",
|
||||||
|
"page" => 2, // page 2 is repeat of page 1
|
||||||
"query" => $search,
|
"query" => $search,
|
||||||
"sm" => "tab_pge",
|
"sm" => "tab_pge",
|
||||||
"where" => "web",
|
"ssc" => "tab.ur.all",
|
||||||
"start" => 1 // increment by number of results each time (16??)
|
"start" => 1 // increment by number of results each time (16??)
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -304,13 +305,13 @@ class naver{
|
|||||||
|
|
||||||
$this->fuckhtml->load($html);
|
$this->fuckhtml->load($html);
|
||||||
|
|
||||||
$results =
|
$jsons =
|
||||||
preg_split(
|
preg_split(
|
||||||
'/entry\.bootstrap\(document\.getElementById\("[a-f0-9-r]+"\), ?/',
|
'/entry\.bootstrap\(document\.getElementById\("[a-f0-9-r]+"\), ?/',
|
||||||
$html
|
$html
|
||||||
);
|
);
|
||||||
|
|
||||||
if(count($results) !== 2){
|
if(count($jsons) <= 1){
|
||||||
|
|
||||||
// this is thrown when no results are found
|
// this is thrown when no results are found
|
||||||
|
|
||||||
@@ -342,32 +343,29 @@ class naver{
|
|||||||
//throw new Exception("Failed to grep results entrypoint");
|
//throw new Exception("Failed to grep results entrypoint");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach($jsons as $json){
|
||||||
|
|
||||||
$json =
|
$json =
|
||||||
json_decode(
|
json_decode(
|
||||||
$this->fuckhtml
|
$this->fuckhtml
|
||||||
->extract_json(
|
->extract_json(
|
||||||
$results[1]
|
$json
|
||||||
),
|
),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
if(!isset($json["body"]["props"]["children"][0]["props"]["children"])){
|
if($json === null){
|
||||||
|
|
||||||
throw new Exception("Failed to access nested children");
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($json["body"]["props"]["children"][0]["props"]["children"] as $result){
|
|
||||||
|
|
||||||
if(
|
|
||||||
!isset($result["templateId"]) ||
|
|
||||||
$result["templateId"] != "webItem"
|
|
||||||
){
|
|
||||||
|
|
||||||
// should not happen
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $result["props"];
|
if(!isset($json["data"]["state"]["items"])){
|
||||||
|
|
||||||
|
//throw new Exception("Failed to access nested children");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($json["data"]["state"]["items"] as $result){
|
||||||
|
|
||||||
// get sublinks
|
// get sublinks
|
||||||
$sublinks = [];
|
$sublinks = [];
|
||||||
@@ -429,12 +427,19 @@ class naver{
|
|||||||
// get date
|
// get date
|
||||||
$time = null;
|
$time = null;
|
||||||
|
|
||||||
if(isset($result["bodyPrefixes"][0]["text"])){
|
if(isset($result["profile"]["createdDate"])){
|
||||||
|
|
||||||
|
$time = $result["profile"]["createdDate"];
|
||||||
|
}elseif(isset($result["sourceProfile"]["createdDate"])){
|
||||||
|
|
||||||
|
$time = $result["sourceProfile"]["createdDate"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if($time !== null){
|
||||||
$date =
|
$date =
|
||||||
strtotime(
|
strtotime(
|
||||||
substr(
|
substr(
|
||||||
$result["bodyPrefixes"][0]["text"],
|
$time,
|
||||||
-1
|
-1
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -442,13 +447,58 @@ class naver{
|
|||||||
if($date !== false){
|
if($date !== false){
|
||||||
|
|
||||||
$time = $date;
|
$time = $date;
|
||||||
|
}else{
|
||||||
|
|
||||||
|
$time = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get title
|
||||||
|
if(isset($result["title"])){
|
||||||
|
|
||||||
|
$title = $result["title"];
|
||||||
|
}elseif(isset($result["questionTitle"])){
|
||||||
|
|
||||||
|
$title = $result["questionTitle"];
|
||||||
|
}else{
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get url
|
||||||
|
if(isset($result["titleHref"])){
|
||||||
|
|
||||||
|
$href = $result["titleHref"];
|
||||||
|
}elseif(isset($result["href"])){
|
||||||
|
|
||||||
|
$href = $result["href"];
|
||||||
|
}elseif(isset($result["answerHref"])){
|
||||||
|
|
||||||
|
$href = $result["answerHref"];
|
||||||
|
}else{
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get description
|
||||||
|
if(isset($result["bodyText"])){
|
||||||
|
|
||||||
|
$description = $result["bodyText"];
|
||||||
|
}elseif(isset($result["content"])){
|
||||||
|
|
||||||
|
$description = $result["content"];
|
||||||
|
}elseif(isset($result["questionContent"])){
|
||||||
|
|
||||||
|
$description = $result["questionContent"];
|
||||||
|
}else{
|
||||||
|
|
||||||
|
$description = null;
|
||||||
|
}
|
||||||
|
|
||||||
$out["web"][] = [
|
$out["web"][] = [
|
||||||
"title" => $this->decode_html($result["title"]),
|
"title" => $this->decode_html($title),
|
||||||
"description" => $this->decode_html($result["bodyText"]),
|
"description" => $this->decode_html($description),
|
||||||
"url" => $result["href"],
|
"url" => $href,
|
||||||
"date" => $time,
|
"date" => $time,
|
||||||
"type" => "web",
|
"type" => "web",
|
||||||
"thumb" => $thumb,
|
"thumb" => $thumb,
|
||||||
@@ -456,6 +506,7 @@ class naver{
|
|||||||
"table" => $table
|
"table" => $table
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// get next page
|
// get next page
|
||||||
$npt =
|
$npt =
|
||||||
|
|||||||
Reference in New Issue
Block a user