Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
zzsn_spider
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
王景浩
zzsn_spider
Commits
7fe3a354
提交
7fe3a354
authored
1月 18, 2024
作者:
LiuLiYuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Edge翻译 01/18
上级
d9bf9b2f
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
23 行增加
和
13 行删除
+23
-13
Edge_pyautogui.py
Translate/Edge_pyautogui.py
+23
-13
没有找到文件。
Translate/Edge_pyautogui.py
浏览文件 @
7fe3a354
import
pyautogui
import
pyautogui
from
bs4
import
BeautifulSoup
from
retry
import
retry
from
retry
import
retry
from
selenium
import
webdriver
from
selenium
import
webdriver
from
selenium.webdriver.common.action_chains
import
ActionChains
from
selenium.webdriver.common.action_chains
import
ActionChains
...
@@ -8,11 +9,16 @@ from selenium.webdriver.support import expected_conditions as EC
...
@@ -8,11 +9,16 @@ from selenium.webdriver.support import expected_conditions as EC
import
time
import
time
from
bson
import
ObjectId
from
bson
import
ObjectId
import
pymongo
import
pymongo
from
base
import
BaseCore
baseCore
=
BaseCore
.
BaseCore
()
log
=
baseCore
.
getLogger
()
db_storage
=
pymongo
.
MongoClient
(
'mongodb://114.115.221.202:27017/'
,
username
=
'admin'
,
password
=
'ZZsn@9988'
)
.
中科软
[
'数据源_0106'
]
# 获取当前活动窗口的标题
# 获取当前活动窗口的标题
def
get_active_window_title
():
def
get_active_window_title
():
window
=
pyautogui
.
getActiveWindow
()
window
=
pyautogui
.
getActiveWindow
()
print
(
f
'当前活动窗口的标题是:{window.title}'
)
log
.
info
(
f
'当前活动窗口的标题是:{window.title}'
)
return
window
.
title
if
window
else
None
return
window
.
title
if
window
else
None
...
@@ -50,32 +56,31 @@ def Translate(_id, driver):
...
@@ -50,32 +56,31 @@ def Translate(_id, driver):
time
.
sleep
(
2
)
time
.
sleep
(
2
)
if
driver
.
find_element
(
By
.
TAG_NAME
,
'body'
)
.
text
[:
500
]
in
flag
:
if
driver
.
find_element
(
By
.
TAG_NAME
,
'body'
)
.
text
[:
500
]
in
flag
:
print
(
f
'{_id}---翻译失败,重试'
)
log
.
error
(
f
'{_id}---翻译失败,重试'
)
# 使用pyautogui模块模拟按下Alt+Tab键,将Edge浏览器置于最前面
# 使用pyautogui模块模拟按下Alt+Tab键,将Edge浏览器置于最前面
# while get_a
# while get_a
# ctive_window_title() != "Edge浏览器":
# ctive_window_title() != "Edge浏览器":
while
'Microsoft Edge'
not
in
get_active_window_title
():
while
'Microsoft Edge'
not
in
get_active_window_title
():
pyautogui
.
hotkey
(
'alt'
,
'tab'
)
pyautogui
.
hotkey
(
'alt'
,
'tab'
)
print
(
'窗口切换操作'
)
log
.
info
(
'窗口切换操作'
)
# pyautogui.hotkey('alt', 'tab')
# pyautogui.hotkey('alt', 'tab')
# 切换到Edge浏览器窗口
# 切换到Edge浏览器窗口
driver
.
switch_to
.
window
(
edge_handle
)
driver
.
switch_to
.
window
(
edge_handle
)
driver
.
refresh
()
driver
.
refresh
()
raise
raise
from
bs4
import
BeautifulSoup
page_source
=
driver
.
page_source
page_source
=
driver
.
page_source
contentWithTag
=
BeautifulSoup
(
page_source
,
'html.parser'
)
contentWithTag
=
BeautifulSoup
(
page_source
,
'html.parser'
)
with
open
(
rf
'C:
\
Users
\
EDY
\
Desktop
\
{_id}.html'
,
'w'
,
encoding
=
'utf-8'
)
as
f
:
db_storage
.
update_one
({
'_id'
:
ObjectId
(
_id
)},{
'$set'
:{
'postCode'
:
'18'
,
'richText'
:
str
(
contentWithTag
)}})
f
.
write
(
str
(
contentWithTag
))
# with open(rf'C:\Users\EDY\Desktop\{_id}.html', 'w', encoding='utf-8') as f:
# f.write(str(contentWithTag))
# print(str(contentWithTag))
# print(str(contentWithTag))
if
__name__
==
"__main__"
:
def
doJob
()
:
driver
=
webdriver
.
Edge
()
driver
=
webdriver
.
Edge
()
while
True
:
db_storage
=
pymongo
.
MongoClient
(
'mongodb://114.115.221.202:27017/'
,
username
=
'admin'
,
password
=
'ZZsn@9988'
)
.
中科软
[
'数据源_0106'
]
datas
=
db_storage
.
find
({
'postCode'
:
'2'
})
.
limit
(
10
)
datas
=
db_storage
.
find
({
'postCode'
:
'2'
})
.
limit
(
10
)
for
data
in
datas
:
for
data
in
datas
:
now
=
time
.
time
()
now
=
time
.
time
()
...
@@ -86,6 +91,11 @@ if __name__ == "__main__":
...
@@ -86,6 +91,11 @@ if __name__ == "__main__":
try
:
try
:
Translate
(
_id
,
driver
)
Translate
(
_id
,
driver
)
log
.
info
(
f
'{_id}翻译用时--{time.time() - now}'
)
except
:
except
:
print
(
'翻译失败'
)
log
.
error
(
f
'{_id}翻译失败'
)
print
(
f
'{_id}翻译用时--{time.time() - now}'
)
\ No newline at end of file
if
__name__
==
"__main__"
:
doJob
()
baseCore
.
close
()
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论