forked from HIllya51/LunaTranslator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
74b0f24
commit d847576
Showing
6 changed files
with
136 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import requests | ||
from urllib.parse import quote | ||
from cishu.cishubase import cishubase | ||
from myutils.utils import get_element_by | ||
import threading, base64, re | ||
|
||
|
||
class japandict(cishubase): | ||
def makelinkbase64(self, link, saver): | ||
html = requests.get( | ||
link, | ||
proxies=self.proxy, | ||
).content | ||
base64_content = base64.b64encode(html).decode("utf-8") | ||
saver[link] = f"data:application/octet-stream;base64,{base64_content}" | ||
|
||
def search(self, word): | ||
url = "https://www.japandict.com/?s={}&lang=eng&list=1".format(quote(word)) | ||
html = requests.get( | ||
url, | ||
proxies=self.proxy, | ||
).text | ||
|
||
res = get_element_by("class", "list-group list-group-flush", html) | ||
if res is None: | ||
return | ||
ts = [] | ||
saver = {} | ||
styles = '<link rel="stylesheet" href="https://www.japandict.com/static/css/japandict.ac087f3ecbc8.css" type="text/css"><link rel="preload" href="https://www.japandict.com/static/JapaneseRadicals-Regular.woff2" as="font"><link rel="preload" href="https://www.japandict.com/static/radicals_font.woff" as="font">' | ||
for link in re.findall('href="(.*?)"', styles): | ||
ts.append(threading.Thread(target=self.makelinkbase64, args=(link, saver))) | ||
ts[-1].start() | ||
for t in ts: | ||
t.join() | ||
for link in saver: | ||
styles = styles.replace(link, saver[link]) | ||
return res + styles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters