def test_get_dictionary(self):
     client = GoogleSearchResults({
         "q": "Coffee",
         "location": "Austin,Texas"
     })
     data = client.get_dictionary()
     self.assertIsNotNone(data.get('local_results'))
Beispiel #2
0
def company_data(companies: list):
    company_results = []

    with open('data/raw_companies.json', 'w') as outfile:
        outfile.write('[')
        for company in companies:
            company_serp_params = {
                "q": company.lower(),
                "location": "New York, United States",
                "hl": "en",
                "gl": "us",
                "google_domain": "google.com"
            }

            company_query = GoogleSearchResults(company_serp_params)
            company_query.BACKEND = 'https://serpapi.com/search'
            company_query.SERP_API_KEY = config.API_KEY
            dictionary_results = company_query.get_dictionary()
            company_results.append(dictionary_results)
            print('completed for {}'.format(company))
            time.sleep(5)
            json.dump(dictionary_results, outfile)
            outfile.write(',')
        outfile.write(']')
    return company_results
Beispiel #3
0
def _get_serpapi_results(params):
    try:
        query = GoogleSearchResults(params)
        # query.BACKEND = 'http://serpapi.com/search'
        query.SERP_API_KEY = config.API_KEY
        dictionary_results = query.get_dictionary()

        return dictionary_results
    except Exception as ex:
        with open('data/serpapi_logs.log', 'a') as f:
            f.writelines(ex)
        return None
def search(keyword):
    query = keyword

    params = {
        "playground": "true",
        "q": query,
        "hl": "en",
        "gl": "us",
        "google_domain": "google.com",
        "api_key": "demo",
    }

    engine_query = GoogleSearchResults(params)
    dictionary_results = engine_query.get_dictionary()
    return dictionary_results
def get_batch(pageNumber):
    params = {
        "q": "apple",
        "location": "Dallas",
        "hl": "en",
        "gl": "us",
        #"google_domain" : "google.com",
        "api_key": "demo",
        "tbm": "isch",
        "ijn": pageNumber,
        "source": "test"
    }

    # TODO Switch to production
    query = GoogleSearchResults(params)
    data = query.get_dictionary()
    print(data)

    # extract link
    links = []
    for item in data['images_results']:
        print(item)
        links.append(item['original'])
    return links
Beispiel #6
0
with open('serp_urls.txt') as content:
    content = [line.rstrip('\n') for line in content]

    for line in content:
        errorType = ''
        params = {
            "q": str(line),
            "location": "Cleveland, Ohio, United States",
            "hl": "en",
            "gl": "us",
            "google_domain": "google.com",
            "api_key": api_key,
        }

        query = GoogleSearchResults(params)
        dictionary_results = query.get_dictionary()
        # print(dictionary_results['knowledge_graph'])

        try:
            name = dictionary_results['knowledge_graph']['title']
            address = dictionary_results['knowledge_graph']['address']
        except KeyError:
            errorType = 'Error'
            row = f'"{line}" ~ No listing exists OR is in local map pack. Perform manual search to verify.\n'
            print(
                f'{line} ~ No listing exists OR is in local map pack. Perform manual search to verify.'
            )
            file.write(row)

        if errorType != 'Error':
            name = dictionary_results['knowledge_graph']['title']
Beispiel #7
0
 def test_get_search_archive(self):
     client = GoogleSearchResults({"q": "Coffee", "location": "Austin,Texas"})
     search_result = client.get_dictionary()
     search_id = search_result.get("search_metadata").get("id")
     archived_search_result = GoogleSearchResults({}).get_search_archive(search_id, 'json')
     self.assertEqual(archived_search_result.get("search_metadata").get("id"), search_id)