Пример #1
0
def ser(q, num_page):
    dots = 1
    search_results = google.search(q, num_page)
    while search_results == []:
        c()
        if dots == 0:
            print("Memuat Page")
        elif dots == 1:
            print("Memuat Page.")
        elif dots == 2:
            print("Memuat Page..")
        elif dots == 3:
            print("Memuat Page...")
            dots = -1
        dots += 1
        search_results = google.search(search, num_page)
    c()
    for result in search_results:
        print()
        print(result.name)
        print()
        print("description:",result.description)
        print()
        print("link:",result.link)
    print()
    print("page",num_page)
Пример #2
0
    def search_query(self, query):
        print("Scrapping: ", query)
        results = [result for result in google.search(query, 1)]
        score = dict()

        query = self.remove_stopwords(query)

        for i, result in enumerate(results):
            result = self.remove_stopwords(result.description)
            for val in query.split():
                if i in score:
                    if val in result:
                        score[i] += 1
                else:
                    score[i] = 0

        try:
            avg, n = sum(score.values()) / len(score.values()), len(
                query.split())
        except ZeroDivisionError:
            return "Cannot fetch results, please try again after a while", -1

        if avg > n // 2:
            return "Real", avg / n
        else:
            return "Fake", avg / n
Пример #3
0
def GoogleURL(site, query):
    #Takes a site homepage URL and query as input and returns google search objects (Google Search API class) for the results
    now = datetime.datetime.now()
    after = now - datetime.timedelta(30)
    print(f"After {after}", flush=True)
    GoogleQuery = (
        "site:%s %s after:2021-01-03" % (site, query)
    )  #in the format: 'site:https://www.wsj.com/ Trump concedes' after:2021-01-01
    num_pages = 1
    search_results = google.search(GoogleQuery, num_pages)
    if not search_results:
        # empty list = google server did not respond
        responseSuccessful = False
        resultsYeilded = False
        search_results = "empty"
        print("if not search_results implemented", flush=True)
    elif search_results[0] == "empty":
        # a list containing "empty" = google responded, but no results yielded
        responseSuccessful = True
        resultsYeilded = False
        search_results = "empty"
        print("search_results = empty, ", flush=True)
    else:
        #  full list of google search objects
        responseSuccessful = True
        resultsYeilded = True
        print("responseSuccessful=True, resultsYielded = True ", flush=True)
    print("Google search result " + f"{search_results[0]}",
          flush=True)  #URL to article
    return search_results
Пример #4
0
def queryGoogle(input):
    num_page = 5
    search_results = google.search(input, num_page)
    resultTitle = []
    resultLink = []
    resultDescription = []
    i = 0
    options = images.ImageOptions()
    for e in search_results:
        resultTitle.append("##" + search_results[i].name)
        resultLink.append(search_results[i].link)
        resultDescription.append(search_results[i].description)
        i += 1
        if (i >= 5):
            break
    return resultTitle, resultLink, resultDescription
Пример #5
0
def handler(q=False):
    if q is False:
        return False
    request = json.loads(q)
    if not request.get('url'):
        return {'error': "Unsupported attributes type"}
    num_page = 1
    res = ""
    # The googleapi module sets a random useragent. The output depends on the useragent.
    # It's better to retry 3 times.
    for retry in range(3):
        search_results = google.search(request['url'], num_page)
        if len(search_results) > 0:
            break
        sleep(retry)
    for i, search_result in enumerate(search_results):
        res += "("+str(i+1)+")" + '\t'
        res += json.dumps(search_result.description, ensure_ascii=False)
        res += '\n\n'
    return {'results': [{'types': mispattributes['output'], 'values':res}]}
Пример #6
0
    for result in search_results:
        print()
        print(result.name)
        print()
        print("description:",result.description)
        print()
        print("link:",result.link)
    print()
    print("page",num_page)
def c():
    os.system("clear")
while True:
    num_page = 1
    search = input("Google Search: ")
    print("Memuat...")
    search_results = google.search(search, num_page)
    while search_results == []:
        
        c()
        
        dots += 1 
        if dots == 0:
            print("Memuat Page")
        elif dots == 1:
            print("Memuat Page.")
        elif dots == 2:
            print("Memuat Page..")
        elif dots == 3:
            print("Memuat Page...")
            
            dots = -1
Пример #7
0
    def test_standard_search(self):
        """Test method to search in google."""

        search = google.search("github")
        self.assertNotEqual(len(search), 0)
Пример #8
0
 def get(series_title):
     search_results = google.search(f"site:mangaupdates.com {series_title}")
     if not search_results:
         raise Exception(
             f'Cannot find Mangaupdates page for series "{series_title}"')
     return search_results[0].link
Пример #9
0
def google_search(sentence):
    num_page = 1
    search_results = google.search(sentence, num_page)
    print(search_results[0].description)