Beispiel #1
0
    def GoogleSearch(self, site_url, srch_term, srch_kywrds="", page=1):
        # Checks only the first search result
        # if match is more than 65%...valid result

        valid_results = []

        from entertainment.xgoogle.search import GoogleSearch

        search_url = "site:" + site_url + " " + srch_term + " " + srch_kywrds
        gs = GoogleSearch(search_url)
        gs.results_per_page = 20
        gs.page = page - 1

        title_words = (srch_term + " " + srch_kywrds).lower().split(" ")

        for result in gs.get_results():
            result_title = (result.title + " " + result.url).lower()

            match_total = float(len(title_words))
            match_count = 0
            for title_word in title_words:
                if title_word in result_title:
                    match_count = match_count + 1

            if (match_count / match_total) > 0.65:
                valid_results.append({"title": result.title, "url": result.url})

        return valid_results