How to Get Google Search Results

What is the correct way to get google search results?

According to http://code.google.com/apis/websearch/ , the Search API has been deprecated -- but there's a replacement, the Custom Search API. Will that do what you want?

If so, a quick Web search turned up https://github.com/alexreisner/google_custom_search , among other gems.

How to get google search results

If you look at the htmlvariable, you can see that the search result links all are nested in <h3 class="r"> tags.

Try to change your getGoogleLinks function to:

getGoogleLinks <- function(google.url) {
doc <- getURL(google.url, httpheader = c("User-Agent" = "R
(2.10.0)"))
html <- htmlTreeParse(doc, useInternalNodes = TRUE, error=function
(...){})
nodes <- getNodeSet(html, "//h3[@class='r']//a")
return(sapply(nodes, function(x) x <- xmlAttrs(x)[["href"]]))
}

How to get Google Search results from an application back-end?

You can use google custom search API ...
Check this out
https://developers.google.com/custom-search/docs/overview

You can use this to search the entire web through a hack
To create a Google Custom Search engine that searches the entire web:

EDIT:

  • From the Google Custom Search homepage ( http://www.google.com/cse/ ), click Create a Custom Search Engine.
  • Type a name and description for your search engine.
  • Under Define your search engine, in the Sites to Search box, enter at least one valid URL (For now, just put www.anyurl.com to get past this screen. More on this later ).
  • Select the CSE edition you want and accept the Terms of Service, then click Next. Select the layout option you want, and then click Next.
    Click any of the links under the Next steps section to navigate to your Control panel.
  • In the left-hand menu, under Control Panel, click Basics.
    In the Search Preferences section, select Search the entire web but emphasize included sites.
  • Click Save Changes.
  • In the left-hand menu, under Control Panel, click Sites.
  • Delete the site you entered during the initial setup process.

extract the number of results from google search

You're actually using the wrong url to query google's search engine. You should be using http://www.google.com/search?q=<query>.

So it'd look like this:

def pyGoogleSearch(word):
address = 'http://www.google.com/search?q='
newword = address + word
page = requests.get(newword)
soup = BeautifulSoup(page.content, 'html.parser')
phrase_extract = soup.find(id="resultStats")
print(phrase_extract)

You also probably just want the text of that element, not the element itself, so you can do something like

phrase_text = phrase_extract.text

or to get the actual value as an integer:

val = int(phrase_extract.text.split(' ')[1].replace(',',''))

How to return exact google search results?

If you are getting the result from API is everything Ok. You cant get same resut from google search everything is based on your cookies, browser history, bookmarks, location etc. You can try searching from two different browser you will get different results.

Getting Google Search Result URLs from Search String or URL

The following approach should fetch you few random links out of the total result links from it's landing page. You may need to kick out some links ending with dots. It's really a difficult job to grab links from google search using requests.

import requests
from bs4 import BeautifulSoup

url = "http://www.google.com/search?q={}&hl=en"

def scrape_google_links(query):
res = requests.get(url.format(query.replace(" ","+")),headers={"User-Agent":"Mozilla/5.0"})
soup = BeautifulSoup(res.text,"lxml")
for result in soup.select(".kCrYT > a > .BNeawe:nth-of-type(2)"):
print(result.text.replace(" › ","/"))

if __name__ == '__main__':
scrape_google_links('cyber security')

Is there a way to find google search results for a certain keyword with javascript?

Yes, you can use Google's api to fetch search result from Google.

But for that you have to get a API key from Google and then you can use google's api to fetch result.

Please check this official link to know example and more.

Here is an example http get request

https://www.googleapis.com/customsearch/v1?key=INSERT_YOUR_API_KEY&cx=017576662512468239146:omuauf_lfve&q=lectures

you can simply request these http get request from your javascript using ajax.
In the above example you can replace the word lectures with the key word that you want to search.

You can find complete reference of using Javascript to request google's api here.



Related Topics



Leave a reply



Submit