Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
zzsn_spider
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
王景浩
zzsn_spider
Commits
14054899
提交
14054899
authored
1月 15, 2024
作者:
LiuLiYuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
百度翻译 01/15
上级
2a165047
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
14 行增加
和
1 行删除
+14
-1
baidufanyi.py
百度翻译/baidufanyi.py
+14
-1
没有找到文件。
百度翻译/baidufanyi.py
浏览文件 @
14054899
#codi
ng:utf-8
#codi
ng:utf-8
...
@@ -5,6 +5,7 @@ import string
...
@@ -5,6 +5,7 @@ import string
import
time
import
time
from
urllib.parse
import
quote
from
urllib.parse
import
quote
import
psutil
import
pymongo
import
pymongo
from
bs4
import
BeautifulSoup
from
bs4
import
BeautifulSoup
from
bson
import
ObjectId
from
bson
import
ObjectId
...
@@ -17,6 +18,7 @@ from selenium.webdriver.support.wait import WebDriverWait
...
@@ -17,6 +18,7 @@ from selenium.webdriver.support.wait import WebDriverWait
from
selenium.webdriver.firefox.service
import
Service
from
selenium.webdriver.firefox.service
import
Service
from
selenium.webdriver.firefox.options
import
Options
from
selenium.webdriver.firefox.options
import
Options
from
selenium.webdriver.common.proxy
import
Proxy
,
ProxyType
from
selenium.webdriver.common.proxy
import
Proxy
,
ProxyType
from
func_timeout
import
func_set_timeout
from
base.BaseCore
import
BaseCore
from
base.BaseCore
import
BaseCore
baseCore
=
BaseCore
()
baseCore
=
BaseCore
()
...
@@ -58,6 +60,14 @@ class Translate():
...
@@ -58,6 +60,14 @@ class Translate():
browser
=
webdriver
.
Firefox
(
firefox_profile
=
profile
,
service
=
service
,
options
=
options
)
browser
=
webdriver
.
Firefox
(
firefox_profile
=
profile
,
service
=
service
,
options
=
options
)
return
browser
return
browser
def
kill_firefox
(
self
):
for
proc
in
psutil
.
process_iter
():
try
:
if
proc
.
name
()
==
"firefox.exe"
:
proc
.
kill
()
except
(
psutil
.
NoSuchProcess
,
psutil
.
AccessDenied
,
psutil
.
ZombieProcess
):
pass
def
translate
(
self
,
sentence
,
lang
):
def
translate
(
self
,
sentence
,
lang
):
sentence_
=
sentence
sentence_
=
sentence
wait
=
WebDriverWait
(
self
.
browser
,
20
)
wait
=
WebDriverWait
(
self
.
browser
,
20
)
...
@@ -91,6 +101,7 @@ class Translate():
...
@@ -91,6 +101,7 @@ class Translate():
result
=
self
.
translate
(
sentence_
,
lang
)
result
=
self
.
translate
(
sentence_
,
lang
)
return
result
return
result
@func_set_timeout
(
90
)
def
get_input_language_type
(
self
,
word
,
wait
):
def
get_input_language_type
(
self
,
word
,
wait
):
self
.
browser
.
get
(
"https://fanyi.baidu.com/"
)
self
.
browser
.
get
(
"https://fanyi.baidu.com/"
)
wait
.
until
(
EC
.
presence_of_element_located
((
By
.
ID
,
"baidu_translate_input"
)))
wait
.
until
(
EC
.
presence_of_element_located
((
By
.
ID
,
"baidu_translate_input"
)))
...
@@ -209,6 +220,8 @@ class Translate():
...
@@ -209,6 +220,8 @@ class Translate():
for
tag
in
html
.
find_all
(
text
=
True
):
for
tag
in
html
.
find_all
(
text
=
True
):
if
tag
.
strip
()
==
''
:
if
tag
.
strip
()
==
''
:
continue
continue
if
self
.
is_website_link
(
str
(
tag
)
.
strip
()):
continue
#print(num,tag)
#print(num,tag)
sentence
=
sentences
[
num
]
sentence
=
sentences
[
num
]
tag
.
replace_with
(
sentence
)
tag
.
replace_with
(
sentence
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论