import os\nimport sys\nimport random\nimport time\nimport urllib3\nfrom bs4 import BeautifulSoup\nfrom concurrent.futures import ThreadPoolExecutor\nfrom threading import Lock\nimport requests\nfrom colorama import Fore, init\n\nnow_time = time.strftime('%Y-%m-%d %H-%M')\n\nlock = Lock()\n\ndef read_dorks(dorks):\n # 读取dorks文件并返回内容\n with open(dorks, mode='r', encoding='utf-8') as file:\n content = [result.strip() for result in file.readlines()]\n return len(content), content\n\ndef google_search(query, filename):\n try:\n urllib3.disable_warnings()\n # 设置保存文件路径\n filename = os.path.join(os.getcwd(), f'{filename}.txt')\n # 设置Google搜索的域名\n domains = ['fr','it','ca','co.uk','ru','co.jp','co.kr','com.au','co.in','com.br','com.ar','com.bg','com.na','co.za','co','co.th','com.nl','co.ug','co.nz','es','se','nl','ch','at','dk','be','pl','fi','ie','pt','gr', 'com.tw', 'com', 'co.uk', 'de', 'ca', 'co.kr', 'com.mx', 'co.za']\n random_domain = random.choice(domains)\n # 构建Google搜索的URL\n url = f'https://www.google.{random_domain}/search?q={query}&num=100'\n headers = {\n 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',\n 'accept-language': 'zh-CN,zh;q=0.9',\n 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.7',\n 'referer': 'https://www.google.com/',\n 'origin': 'https://www.google.com',\n 'Sec-Fetch-Site': 'same-origin',\n 'Sec-Fetch-Mode': 'navigate',\n 'Sec-Fetch-User': '?1',\n 'Sec-Fetch-Dest': 'document'\n }\n proxies = {'http': 'http://127.0.0.1:7890', 'https': 'http://127.0.0.1:7890'}\n # 发送请求获取响应内容\n response = requests.get(url=url, headers=headers, proxies=proxies, verify=False, timeout=10)\n soup = BeautifulSoup(response.content, 'html.parser')\n # 使用BeautifulSoup解析HTML内容,提取搜索结果的URL\n find_div = soup.find_all('div', {'class': 'yuRUbf'})\n urls = [url.findNext('a')['href'] + '\n' for url in find_div if 'google.com' not in url.findNext('a')['href']]\n # 将URL写入文件\n write_urls(filename, urls)\n return len(urls)\n except Exception as e:\n print(Fore.RED + f'{now_time}[Error]{ "-" * 10}>{e}' + Fore.RESET)\n return 0\n\ndef write_urls(filename, urls):\n # 将URL写入文件\n with open(filename, mode='a+', encoding='utf-8') as file:\n file.writelines(urls)\n\nif name == 'main':\n while True:\n try:\n init()\n # 获取用户输入的dorks文件和输出文件名\n dorks_file = input(Fore.YELLOW + f'\n{now_time}[INFO]{ "-" * 10}>input file:' + Fore.RESET)\n filename = input(Fore.YELLOW + f'\n{now_time}[INFO]{ "-" * 10}>output file:' + Fore.RESET)\n # 读取dorks文件\n dork_total_num, query_list = read_dorks(dorks_file)\n dork_finish_num = url_num = 0\n with ThreadPoolExecutor(max_workers=20) as executor:\n for i, query in enumerate(query_list):\n # 使用线程池执行搜索任务\n future = executor.submit(google_search, query, filename)\n url_count = future.result()\n url_num += url_count\n dork_finish_num += 1\n print(Fore.GREEN + f'\r{now_time}[INFO]{ "-" * 10}>get Urlnumber:{url_num} Dorsk number:{dork_finish_num} / {dork_total_num}', end='' + Fore.RESET)\n input(Fore.YELLOW + f'\n\n{now_time}[INFO]{"-" * 10}>final huiche' + Fore.RESET)\n break\n except FileNotFoundError:\n print(Fore.RED + f'{now_time}[Error]{"-" * 10}>file not found' + Fore.RESET)\n except KeyboardInterrupt:\n sys.exit(1


原文地址: https://www.cveoy.top/t/topic/pqQO 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录