示例#1
0
 def test_get_json(self):
     client = GoogleSearchResults({
         "q": "Coffee",
         "engine": "google_scholar"
     })
     data = client.get_json()
     self.assertIsNotNone(data["organic_results"][0]["title"])
 def test_search_google_images(self):
     client = GoogleSearchResults({"q": "coffe", "tbm": "isch"})
     for image_result in client.get_json()['images_results']:
         link = image_result["original"]
         try:
             print("link: " + link)
             # wget.download(link, '.')
         except:
             pass
示例#3
0
		def test_get_json(self):
				client = GoogleSearchResults({"q": "Coffee", "location": "Austin,Texas"})
				data = client.get_json()
				self.assertEqual(data["search_metadata"]["status"], "Success")
				self.assertIsNotNone(data["search_metadata"]["google_url"])
				self.assertIsNotNone(data["search_metadata"]["id"])
				# pp = pprint.PrettyPrinter(indent=2)
				# pp.pprint(data['local_results'])
				self.assertIsNotNone(data['local_results']['places'][0])
示例#4
0
 def test_get_json(self):
     client = GoogleSearchResults({
         "q": "Coffee",
         "location": "Austin,Texas"
     })
     data = client.get_json()
     # pp = pprint.PrettyPrinter(indent=2)
     # pp.pprint(data['local_results'])
     self.assertIsNotNone(data['local_results']['places'][0])
 def test_search_google_shopping(self):
     client = GoogleSearchResults({
         "q": "coffe",  # search client
         "tbm": "shop",  # news
         "tbs": "p_ord:rv",  # last 24h
         "num": 100
     })
     data = client.get_json()
     for shopping_result in data['shopping_results']:
         print(
             str(shopping_result['position']) + " - " +
             shopping_result['title'])
 def test_search_by_location(self):
     for city in ["new york", "paris", "berlin"]:
         location = GoogleSearchResults({}).get_location(
             city, 1)[0]["canonical_name"]
         client = GoogleSearchResults({
             "q": "best coffee shop",  # search client
             "location": location,
             "num": 10,
             "start": 0
         })
         data = client.get_json()
         top_result = data['organic_results'][0]["title"]
         print("top coffee result for " + location + " is: " + top_result)
 def test_search_google_news(self):
     client = GoogleSearchResults({
         "q": "coffe",  # search client
         "tbm": "nws",  # news
         "tbs": "qdr:d",  # last 24h
         "num": 10
     })
     for offset in [0, 1, 2]:
         client.params_dict["start"] = offset * 10
         data = client.get_json()
         for news_result in data['news_results']:
             print(
                 str(news_result['position'] + offset * 10) + " - " +
                 news_result['title'])
示例#8
0
        params = {
            "api_key":
            "5b4695dcbf33b844d77818346074c2268857ec9c42f24202d18cce2fd1709ba3",
            "engine": "google",
            "q": new,
            "location": "London, England, United Kingdom",
            "google_domain": "google.co.uk",
            "gl": "uk",
            "hl": "en",
            "no_cache": "true",
            "device": "mobile",
        }
        client = GoogleSearchResults(params)
        #results = client.get_dict()
        time.sleep(2)
        json_results = client.get_json()

        try:
            for position in json_results['ads']:
                data.append(new + ":" + position['displayed_link'] + ":" +
                            str(position['position']))

                #print (json_results)

            #  with open('fileName.csv', "wb") as csv_file:
            # writer = csv.writer(csv_file, delimiter =":")
            # writer.writerow(data)

        except Exception:
            print("there was an exception:" + new)
            data.append(new + ":" + "bugger-no ads")