From c4bb3815eb11ef45a8ca47ac170756112c8dc5b6 Mon Sep 17 00:00:00 2001 From: lilingfengdev Date: Mon, 10 Jun 2024 16:29:43 +0800 Subject: [PATCH] fix --- main.py | 25 +++++++++++++------------ plugin/engine/bing.py | 14 ++++++++++---- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index 9e0ee35..f2e0118 100644 --- a/main.py +++ b/main.py @@ -1,21 +1,22 @@ from plugin.engine.bing import Bing -from plugin.utils.translate import translate,EN +from plugin.utils.translate import translate, EN -print("欢迎使用插件搜索工具") -keyword = input("请输入关键字:") - -engine = Bing() -for result in engine.search(f"我的世界 {translate(keyword)} 插件"): +def print_result(result): print(result.title) print(result.summary) print(result.url) print("====================") print() -for result in engine.search(f"minecraft {translate(keyword,EN)} plugin"): - print(translate(result.title)) - print(translate(result.summary)) - print(result.url) - print("====================") - print() + +print("欢迎使用插件搜索工具") +while True: + keyword = input("请输入关键字(exit退出):") + if keyword == "exit": + break + + engine = Bing() + + for result in engine.search(keyword): + print_result(result) diff --git a/plugin/engine/bing.py b/plugin/engine/bing.py index c4c3db6..1ac727d 100644 --- a/plugin/engine/bing.py +++ b/plugin/engine/bing.py @@ -5,6 +5,8 @@ import requests from lxml.html import etree +from plugin.utils.translate import translate, EN + class Bing(SearchEngine): def get_bing_url(self, keywords): @@ -14,13 +16,17 @@ def get_bing_url(self, keywords): return bing_url def search(self, keywords) -> typing.List[SearchResult]: + keywords = f"我的世界 {translate(keywords)} 插件" bing_url = self.get_bing_url(keywords) result: typing.List[SearchResult] = [] headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2', 'Accept-Encoding': 'gzip, deflate', - 'cookie': 'DUP=Q=sBQdXP4Rfrv4P4CTmxe4lQ2&T=415111783&A=2&IG=31B594EB8C9D4B1DB9BDA58C6CFD6F39; MUID=196418ED32D66077102115A736D66479; SRCHD=AF=NOFORM; SRCHUID=V=2&GUID=DDFFA87D3A894019942913899F5EC316&dmnchg=1; ENSEARCH=BENVER=1; _HPVN=CS=eyJQbiI6eyJDbiI6MiwiU3QiOjAsIlFzIjowLCJQcm9kIjoiUCJ9LCJTYyI6eyJDbiI6MiwiU3QiOjAsIlFzIjowLCJQcm9kIjoiSCJ9LCJReiI6eyJDbiI6MiwiU3QiOjAsIlFzIjowLCJQcm9kIjoiVCJ9LCJBcCI6dHJ1ZSwiTXV0ZSI6dHJ1ZSwiTGFkIjoiMjAyMC0wMy0xNlQwMDowMDowMFoiLCJJb3RkIjowLCJEZnQiOm51bGwsIk12cyI6MCwiRmx0IjowLCJJbXAiOjd9; ABDEF=V=13&ABDV=11&MRNB=1614238717214&MRB=0; _RwBf=mtu=0&g=0&cid=&o=2&p=&c=&t=0&s=0001-01-01T00:00:00.0000000+00:00&ts=2021-02-25T07:47:40.5285039+00:00&e=; MUIDB=196418ED32D66077102115A736D66479; SerpPWA=reg=1; SRCHUSR=DOB=20190509&T=1614253842000&TPC=1614238646000; _SS=SID=375CD2D8DA85697D0DA0DD31DBAB689D; _EDGE_S=SID=375CD2D8DA85697D0DA0DD31DBAB689D&mkt=zh-cn; _FP=hta=on; SL_GWPT_Show_Hide_tmp=1; SL_wptGlobTipTmp=1; dsc=order=ShopOrderDefault; ipv6=hit=1614260171835&t=4; SRCHHPGUSR=CW=993&CH=919&DPR=1&UTC=480&WTS=63749850642&HV=1614256571&BRW=HTP&BRH=M&DM=0' + 'cookie': 'DUP=Q=sBQdXP4Rfrv4P4CTmxe4lQ2&T=415111783&A=2&IG=31B594EB8C9D4B1DB9BDA58C6CFD6F39; ' + 'MUID=196418ED32D66077102115A736D66479; SRCHD=AF=NOFORM; ' + 'SRCHUID=V=2&GUID=DDFFA87D3A894019942913899F5EC316&dmnchg=1; ENSEARCH=BENVER=1; ' + '_HPVN=CS=eyJQbiI6eyJDbiI6MiwiU3QiOjAsIlFzIjowLCJQcm9kIjoiUCJ9LCJTYyI6eyJDbiI6MiwiU3QiOjAsIlFzIjowLCJQcm9kIjoiSCJ9LCJReiI6eyJDbiI6MiwiU3QiOjAsIlFzIjowLCJQcm9kIjoiVCJ9LCJBcCI6dHJ1ZSwiTXV0ZSI6dHJ1ZSwiTGFkIjoiMjAyMC0wMy0xNlQwMDowMDowMFoiLCJJb3RkIjowLCJEZnQiOm51bGwsIk12cyI6MCwiRmx0IjowLCJJbXAiOjd9; ABDEF=V=13&ABDV=11&MRNB=1614238717214&MRB=0; _RwBf=mtu=0&g=0&cid=&o=2&p=&c=&t=0&s=0001-01-01T00:00:00.0000000+00:00&ts=2021-02-25T07:47:40.5285039+00:00&e=; MUIDB=196418ED32D66077102115A736D66479; SerpPWA=reg=1; SRCHUSR=DOB=20190509&T=1614253842000&TPC=1614238646000; _SS=SID=375CD2D8DA85697D0DA0DD31DBAB689D; _EDGE_S=SID=375CD2D8DA85697D0DA0DD31DBAB689D&mkt=zh-cn; _FP=hta=on; SL_GWPT_Show_Hide_tmp=1; SL_wptGlobTipTmp=1; dsc=order=ShopOrderDefault; ipv6=hit=1614260171835&t=4; SRCHHPGUSR=CW=993&CH=919&DPR=1&UTC=480&WTS=63749850642&HV=1614256571&BRW=HTP&BRH=M&DM=0' } for i in range(1, 3): @@ -36,8 +42,8 @@ def search(self, keywords) -> typing.List[SearchResult]: h3 = li.xpath('./h2/a')[0] p = li.xpath('.//p')[0].xpath('string(.)') url = h3.get('href') - result.append(SearchResult(url=url, title=h3.xpath('string(.)'), summary=p)) - except: - pass + result.append(SearchResult(url=url, title=translate(h3.xpath('string(.)')), summary=translate(p))) + except Exception as pri: + print(pri) return result