Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lilingfengdev committed Jun 10, 2024
1 parent 99068f5 commit c4bb381
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
25 changes: 13 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
@@ -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)
14 changes: 10 additions & 4 deletions plugin/engine/bing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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

0 comments on commit c4bb381

Please sign in to comment.