def searchUrlForString(searchprovider, count, startpage, pages, sleeptime, string, stringurl, savesearch, filename):
    for start in range(startpage, pages):
        if (searchprovider == 'b'):
            pagenr = ((int(start) * int(count)) + 1)
            address = ((((('http://www.bing.com/search?q=instreamset:(url title):' + stringurl) + '&count=') + count) + '&first=') + str(pagenr))
            print(('  [*]  Page number: ' + str((int(start) + 1))))
            uas = LoadUserAgents()
            ua = random.choice(uas)
            headers = {'Connection': 'close', 'User-Agent': ua}
            r = requests.get(address, headers=headers)
            soup = BeautifulSoup(r.text, 'lxml')
            for d in soup.find_all('h2'):
                for a in d.find_all('a', href=True):
                    if (string in a['href']):
                        print((((((bcolors.OKGREEN + '  [') + time.strftime('%H:%M:%S')) + ']  [+]  ') + a['href']) + bcolors.ENDC))
                        if filename:
                            with open(filename, 'a') as file:
                                file.write((a['href'] + '\n'))
                    elif ('0.r.msn.' in a['href']):
                        pass
                    else:
                        pass
            sleep(sleeptime)
        elif (searchprovider == 'g'):
            pagenr = (int(start) * int(count))
            address = ((((('https://www.google.dk/search?q=' + stringurl) + '&num=') + count) + '&start=') + str(pagenr))
            print(('  [*]  Page number: ' + str((int(start) + 1))))
            uas = LoadUserAgents()
            ua = random.choice(uas)
            headers = {'Connection': 'close', 'User-Agent': ua}
            r = requests.get(address, headers=headers)
            soup = BeautifulSoup(r.text, 'lxml')
            for d in soup.find_all('cite'):
                url = d.text
                if (string in url):
                    print((((((bcolors.OKGREEN + '  [') + time.strftime('%H:%M:%S')) + ']  [+]  ') + url) + bcolors.ENDC))
                    if (filename == 'y'):
                        with open(filename, 'a') as file:
                            file.write((url + '\n'))
            sleep(sleeptime)
        try:
            print('')
        except KeyboardInterrupt:
            print(((bcolors.FAIL + '  User input - Ctrl + c') + bcolors.ENDC))
            quitnow = input((((bcolors.ENDC + bcolors.BOLD) + '    Exit program (y/N): ') + bcolors.OKBLUE))
            if (quitnow == 'y'):
                print((bcolors.ENDC + '  // Exiting\n\n'))
                sys.exit()
            else:
                print((bcolors.ENDC + '  // Continuing\n\n'))
        except:
            print(((bcolors.FAIL + '  ERROR!!! ') + bcolors.ENDC))
    print('\n  Done scraping')
    with open(filename) as f:
        resultsnumber = sum((1 for _ in f))
    if (savesearch == 'y'):
        print(('  Scraping saved in file: ' + filename))
        print(('  Total saved urls:  ' + str(resultsnumber)))
    else:
        print(('  Total urls collected:  ' + str(resultsnumber)))
    checkurls = input(((bcolors.ENDC + '\n    Would you like to check urls for vuln (Y/n): ') + bcolors.OKBLUE))
    if (checkurls.lower() not in ('', 'y', 'n')):
        print((bcolors.WARNING + "  - Wrong input - only 'y' and 'n' allowed. Using 'y'"))
        checkurls = 'y'
    if (checkurls == 'n'):
        print((bcolors.ENDC + '  // Exiting\n\n'))
        try:
            os.remove('tmpurllist')
        except OSError:
            pass
        sys.exit()
    else:
        checkUrlsForVuln(filename)
def searchUrlForString(searchprovider, count, startpage, pages, sleeptime, string, stringurl, savesearch, filename):
    for start in range(startpage, pages):
        if (searchprovider == 'b'):
            pagenr = ((int(start) * int(count)) + 1)
            address = ((((('http://www.bing.com/search?q=instreamset:(url title):' + stringurl) + '&count=') + count) + '&first=') + str(pagenr))
            print(('  [*]  Page number: ' + str((int(start) + 1))))
            uas = LoadUserAgents()
            ua = random.choice(uas)
            headers = {'Connection': 'close', 'User-Agent': ua}
            r = requests.get(address, headers=headers)
            soup = BeautifulSoup(r.text, 'lxml')
            for d in soup.find_all('h2'):
                for a in d.find_all('a', href=True):
                    if (string in a['href']):
                        print((((((bcolors.OKGREEN + '  [') + time.strftime('%H:%M:%S')) + ']  [+]  ') + a['href']) + bcolors.ENDC))
                        if filename:
                            with open(filename, 'a') as file:
                                file.write((a['href'] + '\n'))
                    elif ('0.r.msn.' in a['href']):
                        pass
                    else:
                        pass
            sleep(sleeptime)
        elif (searchprovider == 'g'):
            pagenr = (int(start) * int(count))
            address = ((((('https://www.google.dk/search?q=' + stringurl) + '&num=') + count) + '&start=') + str(pagenr))
            print(('  [*]  Page number: ' + str((int(start) + 1))))
            uas = LoadUserAgents()
            ua = random.choice(uas)
            headers = {'Connection': 'close', 'User-Agent': ua}
            r = requests.get(address, headers=headers)
            soup = BeautifulSoup(r.text, 'lxml')
            for d in soup.find_all('cite'):
                url = d.text
                if (string in url):
                    print((((((bcolors.OKGREEN + '  [') + time.strftime('%H:%M:%S')) + ']  [+]  ') + url) + bcolors.ENDC))
                    if (filename == 'y'):
                        with open(filename, 'a') as file:
                            file.write((url + '\n'))
            sleep(sleeptime)
        try:
            print()
        except KeyboardInterrupt:
            print(((bcolors.FAIL + '  User input - Ctrl + c') + bcolors.ENDC))
            quitnow = input((((bcolors.ENDC + bcolors.BOLD) + '    Exit program (y/N): ') + bcolors.OKBLUE))
            if (quitnow == 'y'):
                print((bcolors.ENDC + '  // Exiting\n\n'))
                sys.exit()
            else:
                print((bcolors.ENDC + '  // Continuing\n\n'))
        except:
            print(((bcolors.FAIL + '  ERROR!!! ') + bcolors.ENDC))
    print('\n  Done scraping')
    with open(filename) as f:
        resultsnumber = sum((1 for _ in f))
    if (savesearch == 'y'):
        print(('  Scraping saved in file: ' + filename))
        print(('  Total saved urls:  ' + str(resultsnumber)))
    else:
        print(('  Total urls collected:  ' + str(resultsnumber)))
    checkurls = input(((bcolors.ENDC + '\n    Would you like to check urls for vuln (Y/n): ') + bcolors.OKBLUE))
    if (checkurls.lower() not in (, 'y', 'n')):
        print((bcolors.WARNING + "  - Wrong input - only 'y' and 'n' allowed. Using 'y'"))
        checkurls = 'y'
    if (checkurls == 'n'):
        print((bcolors.ENDC + '  // Exiting\n\n'))
        try:
            os.remove('tmpurllist')
        except OSError:
            pass
        sys.exit()
    else:
        checkUrlsForVuln(filename)