Last active
March 21, 2020 19:54
-
-
Save skyzer/24f80640e99070ec83bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_html_contents($full_url) { | |
return str_get_html($full_url); // simplehtmldom's function | |
} | |
function get_full_result_block($html) { | |
return $html->find('div#center_col', 0); | |
} | |
function get_topstuff($whole_result) { | |
return $whole_result->find('div#topstuff', 0); | |
} | |
function get_best_guess($topstuff) { | |
$best_guess = $this->strstr_after($topstuff->plaintext, 'Best guess for this image:'); | |
return trim($best_guess, ' '); | |
} | |
function get_titles_dom($whole_search_result_block) { | |
return $whole_search_result_block->find('div#search div#ires ol#rso li.g h3.r'); | |
} | |
function get_span_texts_dom($whole_search_result_block) { | |
return $whole_search_result_block->find('div#search div#ires ol#rso li.g span.st'); | |
} | |
function get_first_title($titles_dom) { | |
$results_count = count($titles_dom); | |
for ($i = 0; $i < $results_count; $i++) { | |
$title = $this->filter_out_bad_words($titles_dom[$i]->plaintext); | |
if ($title === 'Visually similar images') return null; | |
if (str_word_count($title) == 1 & $i + 1 != $results_count) { | |
$title .= " ".$this->filter_out_bad_words($titles_dom[$i + 1]->plaintext); | |
} else { | |
return $title; | |
} | |
} | |
return null; | |
} | |
function get_first_span_text($span_texts_dom) { | |
$results_count = count($span_texts_dom); | |
for ($i = 0; $i < $results_count; $i++) { | |
$span_text = $this->filter_out_bad_words($span_texts_dom[$i]->plaintext); | |
if ($span_text === 'Visually similar images') return null; | |
if ($span_text) return $span_text; | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment