Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
zzsn_spider
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
王景浩
zzsn_spider
Commits
33d124a4
提交
33d124a4
authored
1月 12, 2024
作者:
LiuLiYuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
翻译 01-12
上级
fca9d56e
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
27 行增加
和
16 行删除
+27
-16
baidufanyi.py
百度翻译/baidufanyi.py
+27
-16
没有找到文件。
百度翻译/baidufanyi.py
浏览文件 @
33d124a4
#codi
ng:utf-8
#codi
ng:utf-8
...
...
@@ -16,6 +16,7 @@ from selenium.webdriver.support.wait import WebDriverWait
# from selenium.webdriver.chrome.service import Service
from
selenium.webdriver.firefox.service
import
Service
from
selenium.webdriver.firefox.options
import
Options
from
selenium.webdriver.common.proxy
import
Proxy
,
ProxyType
from
base.BaseCore
import
BaseCore
baseCore
=
BaseCore
()
...
...
@@ -42,17 +43,23 @@ class Translate():
# chrome_options.add_argument('--ignore-certificate-errors')
# chrome_options.add_argument("--disable-blink-features=AutomationControlled")
# chrome_options.add_argument("--start-maximized")
# proxy
= baseCore.get_proxy()
proxy_
=
baseCore
.
get_proxy
()
# chrome_options.add_argument('--proxy-server=' + proxy['http'].split('://')[1])
# chrome_options.add_argument(
# 'user-agent=' + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36')
#
# browser = webdriver.Chrome(service=path, chrome_options=chrome_options)
proxy
=
Proxy
()
proxy
.
proxy_type
=
ProxyType
.
MANUAL
proxy
.
http_proxy
=
proxy_
[
'http'
]
.
split
(
'://'
)[
1
]
proxy
.
ssl_proxy
=
proxy_
[
'http'
]
.
split
(
'://'
)[
1
]
service
=
Service
(
r'F:\spider\firefox\geckodriver_1.exe'
)
options
=
Options
()
options
.
set_preference
(
"general.useragent.override"
,
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"
)
browser
=
webdriver
.
Firefox
(
options
=
options
,
service
=
service
)
capabilities
=
webdriver
.
DesiredCapabilities
.
FIREFOX
proxy
.
add_to_capabilities
(
capabilities
)
browser
=
webdriver
.
Firefox
(
options
=
options
,
service
=
service
,
capabilities
=
capabilities
)
return
browser
def
translate
(
self
,
sentence
,
lang
):
...
...
@@ -147,10 +154,13 @@ class Translate():
sentence
=
str
(
tag
)
.
strip
()
tag_list
.
append
(
sentence
)
sentence
=
''
num
=
0
for
tag
in
tag_list
:
if
tag
==
''
:
if
tag
.
strip
()
==
''
:
continue
sentence
+=
f
'{tag}😊'
num
+=
1
#print(num)
# if len(sentence) == 1:
# continue
# if sentence == '\n' or sentence == '\t' or sentence == ' ':
...
...
@@ -193,23 +203,24 @@ class Translate():
break
#print(result)
sentences
=
result
.
split
(
'😊'
)
print
(
len
(
sentences
))
#
print(len(sentences))
num
=
0
for
tag
in
html
.
find_all
(
text
=
True
):
if
tag
==
''
:
if
tag
.
strip
()
==
''
:
continue
#print(num,tag)
sentence
=
sentences
[
num
]
tag
.
replace_with
(
sentence
)
num
+=
1
return
str
(
html
.
prettify
())
+
'<p/><br>译文来源:微软自动翻译<br></p>'
if
__name__
==
"__main__"
:
test
=
Translate
()
db_storage
=
pymongo
.
MongoClient
(
'mongodb://114.115.221.202:27017/'
,
username
=
'admin'
,
password
=
'ZZsn@9988'
)
.
中科软
[
'数据源_0504'
]
data
=
db_storage
.
find_one
({
'_id'
:
ObjectId
(
'656f14e84d6d77428c713271'
)})
a
=
data
[
'richTextForeign'
]
result
=
test
.
gethtml
(
a
)
print
(
result
)
test
.
close
()
\ No newline at end of file
# if __name__ == "__main__":
# test = Translate()
# db_storage = pymongo.MongoClient('mongodb://114.115.221.202:27017/', username='admin', password='ZZsn@9988').中科软[
# '数据源_0504']
# data = db_storage.find_one({'_id': ObjectId('656f14e84d6d77428c713271')})
# a = data['richTextForeign']
# result = test.gethtml(a)
# print(result)
# test.close()
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论