Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
N
network-assets-reptile
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liyang
network-assets-reptile
Commits
a96392d1
Commit
a96392d1
authored
Jul 20, 2023
by
liyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:debug ptt
parent
8229ccc5
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
32 deletions
+9
-32
createBrowserDriver.py
utils/createBrowserDriver.py
+9
-32
No files found.
utils/createBrowserDriver.py
View file @
a96392d1
...
@@ -28,42 +28,17 @@ def create(option=None, using_user_data=True, web_browser="firefox"):
...
@@ -28,42 +28,17 @@ def create(option=None, using_user_data=True, web_browser="firefox"):
# 安装或升级 chromedriver
# 安装或升级 chromedriver
# chromedriver_autoinstaller.install()
# chromedriver_autoinstaller.install()
def
get_user_data_dir
():
"""
:return:
"""
# 获取现有Chrome浏览器用户数据目录
user_data_dir
=
os
.
path
.
join
(
os
.
path
.
abspath
(
"../"
),
'network-assets-reptile'
,
'user_data'
)
# if platform.system() == 'Windows':
# if web_browser == "firefox":
# user_data_dir = os.path.join(os.environ['USERPROFILE'], 'AppData', 'Local', 'Mozilla', 'Firefox',
# 'Profiles')
# else:
# user_data_dir = os.path.join(os.environ['USERPROFILE'], 'AppData', 'Local', 'Google', 'Chrome',
# 'User Data')
# elif platform.system() == 'Linux':
# if web_browser == "firefox":
# user_data_dir = os.path.join(os.path.expanduser('~'), '.config', 'Firefox', 'Profiles','huqg7mpy.default-release')
# else:
# user_data_dir = os.path.join(os.path.expanduser('~'), '.config', 'google-chrome')
# elif platform.system() == 'Darwin':
# if web_browser == "firefox":
# user_data_dir = os.path.join(os.path.expanduser("~"), 'Library', 'Application Support', 'Firefox',
# 'Profiles','huqg7mpy.default-release')
# else:
# user_data_dir = os.path.join(os.path.expanduser("~"), 'Library', 'Application Support', 'Google',
# 'Chrome')
# else:
# raise Exception('Unsupported operating system')
return
user_data_dir
options
=
""
options
=
""
browser
=
""
browser
=
""
# 获取现有Chrome浏览器用户数据目录
user_data_dir
=
os
.
path
.
join
(
os
.
path
.
abspath
(
"../"
),
'network-assets-reptile'
,
'user_data'
)
if
web_browser
==
"firefox"
:
if
web_browser
==
"firefox"
:
options
=
webdriver
.
FirefoxOptions
()
options
=
webdriver
.
FirefoxOptions
()
else
:
else
:
options
=
webdriver
.
ChromeOptions
()
options
=
webdriver
.
ChromeOptions
()
if
option
is
not
None
:
if
option
is
not
None
:
for
value
in
option
:
for
value
in
option
:
options
.
add_argument
(
value
)
options
.
add_argument
(
value
)
...
@@ -71,11 +46,11 @@ def create(option=None, using_user_data=True, web_browser="firefox"):
...
@@ -71,11 +46,11 @@ def create(option=None, using_user_data=True, web_browser="firefox"):
if
using_user_data
:
if
using_user_data
:
# 添加用户数据目录参数,启用浏览器的持久性会话,可以保存登录状态和Cookie
# 添加用户数据目录参数,启用浏览器的持久性会话,可以保存登录状态和Cookie
if
web_browser
==
"firefox"
:
if
web_browser
==
"firefox"
:
firefox_profile_path
=
get_user_data_dir
()
# 将此处替换为你的Firefox用户数据目录路径
firefox_profile_path
=
user_data_dir
# 将此处替换为你的Firefox用户数据目录路径
profile
=
FirefoxProfile
(
profile_directory
=
firefox_profile_path
)
profile
=
FirefoxProfile
(
profile_directory
=
firefox_profile_path
)
options
.
profile
=
profile
options
.
profile
=
profile
else
:
else
:
options
.
add_argument
(
f
'--user-data-dir={
get_user_data_dir()
}'
)
options
.
add_argument
(
f
'--user-data-dir={
user_data_dir
}'
)
# if sys.platform.startswith('linux'):
# if sys.platform.startswith('linux'):
# print("当前系统是 Linux")
# print("当前系统是 Linux")
...
@@ -94,9 +69,11 @@ def create(option=None, using_user_data=True, web_browser="firefox"):
...
@@ -94,9 +69,11 @@ def create(option=None, using_user_data=True, web_browser="firefox"):
extend
=
""
extend
=
""
if
platform
.
system
()
==
'Windows'
:
if
platform
.
system
()
==
'Windows'
:
extend
=
".exe"
extend
=
".exe"
geckodriver_path
=
os
.
path
.
join
(
os
.
path
.
abspath
(
"./"
),
"drive"
,
"geckodriver"
,
extend
)
print
(
f
"windows系统需要设置驱动程序路径:{geckodriver_path}"
)
options
.
binary_location
=
geckodriver_path
else
:
else
:
extend
=
""
extend
=
""
geckodriver_path
=
os
.
path
.
join
(
os
.
path
.
abspath
(
"./"
),
"drive"
,
"geckodriver"
,
extend
)
browser
=
webdriver
.
Firefox
(
options
=
options
)
browser
=
webdriver
.
Firefox
(
options
=
options
)
else
:
else
:
# 创建Chrome浏览器对象并传入选项
# 创建Chrome浏览器对象并传入选项
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment