chevron_left chevron_right
Login Register invert_colors photo_library


Stay updated and chat with others! - Join the Discord!
Thread Rating:
  • 0 Vote(s) - 0 Average


GiyPy (Google Search Explained) filter_list
Author
Message
GiyPy (Google Search Explained) #1
This is an explanation to the google search for GiyPy

I'm not good at explaining things, but here goes nothing...

Taking you step by step, We start by generating a url using whatever search you input.

So for example, if I were to search for kittens, I would end up with this URL.
Code:
http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=kittens
We then use the Python module, Urllib to open, parse, read and decode the data.
Code:
encoded = urllib.parse.quote("kittens")
rawData = urllib.request.urlopen("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q="+encoded).read().decode("utf-8")
Now that we have our raw data, we can use json.loads to take a JSON string and turn it into a python dictionary.
From there, we can easily get the information we need.
Code:
jsonData = json.loads(rawData)

This is what the json data looks like:
Code:
{"responseData": {"results":[{"GsearchResultClass":"GwebSearch","unescapedUrl":"http://www.youtube.com/watch?v\u003dFtX8nswnUKU","url":"http://www.youtube.com/watch%3Fv%3DFtX8nswnUKU","visibleUrl":"www.youtube.com","cacheUrl":"http://www.google.com/search?q\u003dcache:SipO1qfqbp8J:www.youtube.com","title":"\u003cb\u003ekittens\u003c/b\u003e inspired by \u003cb\u003ekittens\u003c/b\u003e - YouTube","titleNoFormatting":"kittens inspired by kittens - YouTube","content":"Sep 1, 2008 \u003cb\u003e...\u003c/b\u003e The Official Facebook Page- https://www.facebook.com/pages/\u003cb\u003eKittens\u003c/b\u003e-Inspired-by\n-\u003cb\u003eKittens\u003c/b\u003e/49930012799."}]}}

Now, You are probably thinking what the fuck is this crap.
Because I did the same :|
Bunched together, Its a little hard to understand, but if we split it apart, it becomes alot easier to read.

Code:
{"responseData":
{"results":
[{"GsearchResultClass":
"GwebSearch",
"unescapedUrl":"http://www.youtube.com/watch?v\u003dFtX8nswnUKU",
"url":"http://www.youtube.com/watch%3Fv%3DFtX8nswnUKU",
"visibleUrl":"www.youtube.com",
"cacheUrl":"http://www.google.com/search?q\u003dcache:SipO1qfqbp8J:www.youtube.com",
"title":"\u003cb\u003ekittens\u003c/b\u003e inspired by \u003cb\u003ekittens\u003c/b\u003e - YouTube",
"titleNoFormatting":"kittens inspired by kittens - YouTube",
"content":"Sep 1, 2008 \u003cb\u003e...\u003c/b\u003e The Official Facebook Page- https://www.facebook.com/pages/\u003cb\u003eKittens\u003c/b\u003e-Inspired-by\n-\u003cb\u003eKittens\u003c/b\u003e/49930012799."
}]}}

As you can see, it begins the entire dictionary with resonseData, shortly followed by results.
Inside that is all the information we need.

Since we converted the data to a python dictionary, we can very easily select the data we need like so:
Code:
data = jsonData["responseData"]["results"][0]

if we look at the jsonData as a box, we have something like this:

[Image: screenshot_34.png]

Inside the responseData is results. Inside results is four lots of gSearchResultClass and in each of them there is more information.

The previous code opens the responseData box and the results box, Then opens the first box it finds. ( 0 is the first, 1 is the second ect )

All we need to do now is unquote the data, and print what we want.

Code:
title = data["title"]
link = urllib.parse.unquote(data["url"])

print("I found: %s \n %s" % (title, link))

This returns:

Code:
I found: kittens inspired by kittens - YouTube
http://www.youtube.com/watch?v=FtX8nswnUKU


If this isn't explained enough, or im completely wrong, Please feel free to post a reply with whatever I failed at.
[Image: screenshot_108.png]

Reply






Users browsing this thread: 1 Guest(s)