async def googletest(context): """ Searches Google for a string. """ mg = MagicGoogle() reply = await context.get_reply_message() query = context.arguments if query: pass elif reply: query = reply.text else: await context.edit(lang('arg_error')) return query = query.replace(' ', '+') if not silent: await context.edit(lang('google_processing')) results = "" for i in mg.search(query=query, num=int(config['result_length'])): try: title = i['text'][0:30] + '...' link = i['url'] results += f"\n[{title}]({link}) \n" except: await context.edit(lang('google_connection_error')) return await context.edit(f"**Google** |`{query}`| 🎙 🔍 \n" f"{results}", link_preview=False) await log(f"{lang('google_success')} `{query}`")
async def googletest(context): """ Searches Google for a string. """ mg = MagicGoogle() reply = await context.get_reply_message() query = context.arguments if query: pass elif reply: query = reply.text else: await context.edit("出错了呜呜呜 ~ 无效的参数。") return query = query.replace(' ', '+') await context.edit("正在拉取结果 . . .") results = "" for i in mg.search(query=query, num=int(config['result_length'])): try: title = i['text'][0:30] + '...' link = i['url'] results += f"\n[{title}]({link}) \n" except: await context.edit("连接到 google服务器 失败") return await context.edit(f"**Google** |`{query}`| 🎙 🔍 \n" f"{results}", link_preview=False) await log(f"在Google搜索引擎上查询了 `{query}`")
'http': 'http://127.0.0.1:1087', 'https': 'http://127.0.0.1:1087' }] # Or MagicGoogle() #mg = MagicGoogle(PROXIES) mg = MagicGoogle() search_key = input("Enter the Search Keyword: ") # The first page of results # result = mg.search_page(query='python') # print(result) # # time.sleep(random.randint(1, 5)) # Get {'title','url','text'} for i in mg.search(query=str(search_key), num=1, language='en'): pprint.pprint(i) time.sleep(random.randint(1, 5)) # Output # {'text': 'The official home of the Python Programming Language.', # 'title': 'Welcome to Python .org', # 'url': 'https://www.python.org/'} # Get first page for url in mg.search_url(query=str(search_key)): pprint.pprint(url) time.sleep(random.randint(1, 5))
# """ ################################################# PROXIES = [{'http': 'http://127.0.0.1:1087', 'https': 'http://127.0.0.1:1087'}] # Or MagicGoogle() mg = MagicGoogle(PROXIES) # The first page of results # result = mg.search_page(query='python') # print(result) # # time.sleep(random.randint(1, 5)) # Get {'title','url','text'} for i in mg.search(query='python', num=1, language='en'): pprint.pprint(i) time.sleep(random.randint(1, 5)) # Output # {'text': 'The official home of the Python Programming Language.', # 'title': 'Welcome to Python .org', # 'url': 'https://www.python.org/'} # Get first page for url in mg.search_url(query='python'): pprint.pprint(url) time.sleep(random.randint(1, 5))
import sys from magic_google import MagicGoogle import pprint mg = MagicGoogle() for i in mg.search(query=sys.argv[1], num=10): pprint.pprint(i)