Skip to content

Instantly share code, notes, and snippets.

@skyzer
Last active March 21, 2020 19:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skyzer/24f80640e99070ec83bc to your computer and use it in GitHub Desktop.
Save skyzer/24f80640e99070ec83bc to your computer and use it in GitHub Desktop.
<?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