Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
zzsn_spider
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
王景浩
zzsn_spider
Commits
2a165047
提交
2a165047
authored
1月 12, 2024
作者:
LiuLiYuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fanyi 01-12
上级
33d124a4
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
21 行增加
和
20 行删除
+21
-20
baidufanyi.py
百度翻译/baidufanyi.py
+21
-20
没有找到文件。
百度翻译/baidufanyi.py
浏览文件 @
2a165047
#codi
ng:utf-8
#codi
ng:utf-8
...
...
@@ -35,31 +35,27 @@ class Translate():
def
close
(
self
):
self
.
browser
.
quit
()
def
is_website_link
(
self
,
string
):
pattern
=
r"^(http|https)?(://)?[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+(/[a-zA-Z0-9-_.?=/]*)?$"
if
re
.
match
(
pattern
,
string
):
return
True
else
:
return
False
def
createDriver
(
self
):
# chrome_driver = r'F:\spider\117\chromedriver-win64\chromedriver.exe'
# path = Service(chrome_driver)
# chrome_options = webdriver.ChromeOptions()
# chrome_options.add_argument('--disable-gpu')
# 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
()
# 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
]
profile
=
webdriver
.
FirefoxProfile
()
profile
.
set_preference
(
'network.proxy.type'
,
1
)
profile
.
set_preference
(
'network.proxy.http'
,
proxy_
[
'http'
]
.
split
(
'://'
)[
1
]
.
split
(
':'
)[
0
])
profile
.
set_preference
(
'network.proxy.http_port'
,
int
(
proxy_
[
'http'
]
.
split
(
'://'
)[
1
]
.
split
(
':'
)[
1
]))
profile
.
set_preference
(
'network.proxy.ssl'
,
proxy_
[
'http'
]
.
split
(
'://'
)[
1
]
.
split
(
':'
)[
0
])
profile
.
set_preference
(
'network.proxy.ssl_port'
,
int
(
proxy_
[
'http'
]
.
split
(
'://'
)[
1
]
.
split
(
':'
)[
1
]))
profile
.
update_preferences
()
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"
)
capabilities
=
webdriver
.
DesiredCapabilities
.
FIREFOX
proxy
.
add_to_capabilities
(
capabilities
)
browser
=
webdriver
.
Firefox
(
options
=
options
,
service
=
service
,
capabilities
=
capabilities
)
browser
=
webdriver
.
Firefox
(
firefox_profile
=
profile
,
service
=
service
,
options
=
options
)
return
browser
def
translate
(
self
,
sentence
,
lang
):
...
...
@@ -158,6 +154,8 @@ class Translate():
for
tag
in
tag_list
:
if
tag
.
strip
()
==
''
:
continue
if
self
.
is_website_link
(
str
(
tag
)
.
strip
()):
continue
sentence
+=
f
'{tag}😊'
num
+=
1
#print(num)
...
...
@@ -170,6 +168,9 @@ class Translate():
#print(sentence)
result
=
''
while
True
:
if
len
(
sentence
.
strip
())
==
1
and
self
.
is_punctuation
(
sentence
.
strip
()):
result
+=
sentence
break
if
len
(
sentence
)
>
1000
:
index_1000
=
sentence
[
999
]
# 判断该字符是不是逗号或句号
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论