jigen7 Posted September 13, 2007 Share Posted September 13, 2007 does anybody know how to get or save the result of google search into php without using any API so i can get to display its top 5 url in a certain keyword for that search. Quote Link to comment https://forums.phpfreaks.com/topic/69258-helphow-to-get-the-url-of-a-google-search-result-without-using-api/ Share on other sites More sharing options...
btherl Posted September 14, 2007 Share Posted September 14, 2007 I use an html parser to process the google SERP and extract the link data. Quote Link to comment https://forums.phpfreaks.com/topic/69258-helphow-to-get-the-url-of-a-google-search-result-without-using-api/#findComment-348128 Share on other sites More sharing options...
jigen7 Posted September 14, 2007 Author Share Posted September 14, 2007 thx ill try it ,can u show it to me how it is done as a basis only thx?? Quote Link to comment https://forums.phpfreaks.com/topic/69258-helphow-to-get-the-url-of-a-google-search-result-without-using-api/#findComment-348197 Share on other sites More sharing options...
btherl Posted September 14, 2007 Share Posted September 14, 2007 I might as well give you the whole thing .. keep in mind that this may break each time google subtly alters their SERP format. <?php function fetch_google_results($content) { $parser = new HtmlParser($content); $display = false; $rank = 0; $urls = array(); while ($parser->parse()) { if ($parser->iNodeType == NODE_TYPE_ELEMENT && $parser->iNodeName == 'blockquote' && $parser->iNodeAttributes['class'] == 'g') { /* Find the end of the blockquote */ while ($parser->parse()) { if ($parser->iNodeType == NODE_TYPE_ENDELEMENT && $parser->iNodeName == 'blockquote') { break; } } } if ($parser->iNodeType == NODE_TYPE_ELEMENT && $parser->iNodeName == 'div' && $parser->iNodeAttributes['class'] == 'g') { while ($parser->parse()) { if ($parser->iNodeType == NODE_TYPE_ELEMENT && $parser->iNodeName == 'a') { break; } }; $url = $parser->iNodeAttributes['href']; if ($url == '') continue; $rank++; $urls[$rank]['url'] = $url; // print "$rank: $url\n"; /* Title can contain bold tags. Identify it by anchor tags */ $title = ''; while ($parser->parse()) { if ($parser->iNodeType == NODE_TYPE_ENDELEMENT && $parser->iNodeName == 'a') { break; } if ($parser->iNodeType == NODE_TYPE_TEXT) { $title .= $parser->iNodeValue; } } $urls[$rank]['title'] = $title; /* Fetch the extract from the page itself */ /* We stop when we find a <td> */ while ($parser->parse()) { if ($parser->iNodeType == NODE_TYPE_ELEMENT && $parser->iNodeName == 'td') { break; } } $parser->parse(); /* <font size="-1"> */ $description = ''; while ($parser->parse()) { /* Ends with a span tag */ if ($parser->iNodeType == NODE_TYPE_ELEMENT && $parser->iNodeName == 'span') { break; } if ($parser->iNodeType == NODE_TYPE_TEXT) { $description .= $parser->iNodeValue; } } $urls[$rank]['description'] = $description; } } return $urls; } Quote Link to comment https://forums.phpfreaks.com/topic/69258-helphow-to-get-the-url-of-a-google-search-result-without-using-api/#findComment-348204 Share on other sites More sharing options...
maxudaskin Posted September 14, 2007 Share Posted September 14, 2007 Just use the following link... http://www.google.ca/search?hl=en&q=this+is+my+search&btnG=Google+Search&meta= so http://www.google.ca/search?hl=en&q=this+is+my+search&btnG=Google+Search&meta= Language is BLUE Search text is LIME GREEN, words separated by + Submit button is PINK, this is important as the search page will not display results with out this. Quote Link to comment https://forums.phpfreaks.com/topic/69258-helphow-to-get-the-url-of-a-google-search-result-without-using-api/#findComment-348210 Share on other sites More sharing options...
jigen7 Posted September 15, 2007 Author Share Posted September 15, 2007 hmm its not returniing anything...correct me if im wrong ill look it up again thx for the function Quote Link to comment https://forums.phpfreaks.com/topic/69258-helphow-to-get-the-url-of-a-google-search-result-without-using-api/#findComment-348758 Share on other sites More sharing options...
d.shankar Posted October 1, 2007 Share Posted October 1, 2007 Just use the following link... http://www.google.ca/search?hl=en&q=this+is+my+search&btnG=Google+Search&meta= so http://www.google.ca/search?hl=en&q=this+is+my+search&btnG=Google+Search&meta= Language is BLUE Search text is LIME GREEN, words separated by + Submit button is PINK, this is important as the search page will not display results with out this. So how is it possible to filter the links ?? By using Regex ?? Quote Link to comment https://forums.phpfreaks.com/topic/69258-helphow-to-get-the-url-of-a-google-search-result-without-using-api/#findComment-359083 Share on other sites More sharing options...
d.shankar Posted October 1, 2007 Share Posted October 1, 2007 I might as well give you the whole thing .. keep in mind that this may break each time google subtly alters their SERP format. Buddy what is SERP Format ??? Quote Link to comment https://forums.phpfreaks.com/topic/69258-helphow-to-get-the-url-of-a-google-search-result-without-using-api/#findComment-359095 Share on other sites More sharing options...
btherl Posted October 2, 2007 Share Posted October 2, 2007 SERP = Search Engine Result Page When you do a search and get a list of results, that list of results is the "SERP" (as well as everything else on that page) Quote Link to comment https://forums.phpfreaks.com/topic/69258-helphow-to-get-the-url-of-a-google-search-result-without-using-api/#findComment-360035 Share on other sites More sharing options...
d.shankar Posted October 2, 2007 Share Posted October 2, 2007 Fine .. I got it btherl. In your code i get class not found error. $parser = new HtmlParser($content); What class are you using ?? can you make it in DOM ? Quote Link to comment https://forums.phpfreaks.com/topic/69258-helphow-to-get-the-url-of-a-google-search-result-without-using-api/#findComment-360039 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.