async def gsearch(q_event): man = await edit_or_reply(q_event, "`Processing...`") match = q_event.pattern_match.group(1) page = re.findall(r"-p\d+", match) lim = re.findall(r"-l\d+", match) try: page = page[0] page = page.replace("-p", "") match = match.replace("-p" + page, "") except IndexError: page = 1 try: lim = lim[0] lim = lim.replace("-l", "") match = match.replace("-l" + lim, "") lim = int(lim) if lim <= 0: lim = int(5) except IndexError: lim = 5 smatch = match.replace(" ", "+") search_args = (str(smatch), int(page)) gsearch = GoogleSearch() bsearch = BingSearch() ysearch = YahooSearch() try: gresults = await gsearch.async_search(*search_args) except NoResultsOrTrafficError: try: gresults = await bsearch.async_search(*search_args) except NoResultsOrTrafficError: try: gresults = await ysearch.async_search(*search_args) except Exception as e: return await edit_delete(man, f"**ERROR:**\n`{e}`", time=10) msg = "" for i in range(lim): if i > len(gresults["links"]): break try: title = gresults["titles"][i] link = gresults["links"][i] desc = gresults["descriptions"][i] msg += f"👉 [{title}]({link})\n`{desc}`\n\n" except IndexError: break await edit_or_reply( man, "**Keyword Google Search:**\n`" + match + "`\n\n**Results:**\n" + msg, link_preview=False, aslink=True, linktext=f"**Hasil Pencarian untuk Keyword** `{match}` **adalah** :", )
base_path = "D:\\anaconda\\" os.environ['PATH'] = '%s%s' % ( os.environ['PATH'], join(base_path, 'Library', 'bin'), ) from search_engine_parser import YahooSearch, GoogleSearch, BingSearch import pandas as pd import pprint import tqdm from joblib import Parallel, delayed gsearch = GoogleSearch() ysearch = YahooSearch() bsearch = BingSearch() data = [] nouns_df = pd.read_csv('./data/training_data/synsets_nouns.tsv', sep='\t') def gather(row): # pprint.pprint(row,indent=2) for word in row[1].split(","): datum = [row[0],word] search_args = ('что такое %s?'%word, 1) try: gres = gsearch.search(*search_args) yres = ysearch.search(*search_args) bres = bsearch.search(*search_args) a = [ gres['titles'],
async def gsearch(q_event): "Google search command." catevent = await edit_or_reply(q_event, "`searching........`") match = q_event.pattern_match.group(1) page = re.findall(r"-p\d+", match) lim = re.findall(r"-l\d+", match) try: page = page[0] page = page.replace("-p", "") match = match.replace(f"-p{page}", "") except IndexError: page = 1 try: lim = lim[0] lim = lim.replace("-l", "") match = match.replace(f"-l{lim}", "") lim = int(lim) if lim <= 0: lim = int(5) except IndexError: lim = 5 # smatch = urllib.parse.quote_plus(match) smatch = match.replace(" ", "+") search_args = (str(smatch), int(page)) gsearch = GoogleSearch() bsearch = BingSearch() ysearch = YahooSearch() try: gresults = await gsearch.async_search(*search_args) except NoResultsOrTrafficError: try: gresults = await bsearch.async_search(*search_args) except NoResultsOrTrafficError: try: gresults = await ysearch.async_search(*search_args) except Exception as e: return await edit_delete(catevent, f"**Error:**\n`{e}`", time=10) msg = "" for i in range(lim): if i > len(gresults["links"]): break try: title = gresults["titles"][i] link = gresults["links"][i] desc = gresults["descriptions"][i] msg += f"👉[{title}]({link})\n`{desc}`\n\n" except IndexError: break await edit_or_reply( catevent, "**Search Query:**\n`" + match + "`\n\n**Results:**\n" + msg, link_preview=False, aslink=True, linktext=f"**The search results for the query **__{match}__ **are** :", ) if BOTLOG: await q_event.client.send_message( BOTLOG_CHATID, f"Google Search query `{match}` was executed successfully", )
import search_engine_parser from search_engine_parser import YahooSearch, GoogleSearch, BingSearch, AolSearch, BaiduSearch, DuckDuckGoSearch search = input('Enter your search query: ') search_args = (search, 1) gsearch = GoogleSearch() ysearch = YahooSearch() bsearch = BingSearch() asearch = AolSearch() b2search = BaiduSearch() dsearch = DuckDuckGoSearch() gresults = gsearch.search(*search_args) yresults = ysearch.search(*search_args) bresults = bsearch.search(*search_args) aresults = asearch.search(*search_args) b2results = b2search.search(*search_args) dresults = dsearch.search(*search_args) for i in range(10): print(gresults["titles"][i]) print(gresults["links"][i]) print(gresults["descriptions"][i]) print(yresults["titles"][i]) print(yresults["links"][i]) print(yresults["descriptions"][i]) print(dresults["titles"][i]) print(dresults["links"][i])