Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
ne-shield-publiccenter
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit a24f3bd0
authored
Jul 18, 2022
by
levphon
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
优化代码参数
1 parent
28c271d5
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
7 deletions
src/main/java/cn/com/glsx/base/modules/controller/BrowserController.java
src/main/java/cn/com/glsx/base/modules/controller/BrowserController.java
View file @
a24f3bd
...
@@ -35,10 +35,16 @@ public class BrowserController {
...
@@ -35,10 +35,16 @@ public class BrowserController {
@GetMapping
(
"/screenshot"
)
@GetMapping
(
"/screenshot"
)
public
R
<
String
>
screenshot
(
@RequestParam
(
"url"
)
String
url
,
public
R
<
String
>
screenshot
(
@RequestParam
(
"url"
)
String
url
,
String
selector
,
String
selector
,
Integer
timeout
,
String
filename
,
String
filename
,
Integer
timeout
,
Integer
quality
)
throws
IOException
,
InterruptedException
{
Integer
quality
)
throws
IOException
,
InterruptedException
{
//设置默认参数
selector
=
StringUtils
.
isNotEmpty
(
selector
)
?
selector
:
"selector"
;
filename
=
StringUtils
.
isNotEmpty
(
filename
)
?
filename
:
SnowFlake
.
nextSerialNumber
();
timeout
=
timeout
!=
null
?
timeout
:
1000
*
10
;
quality
=
quality
!=
null
?
quality
:
80
;
Page
page
=
browser
.
newPage
();
Page
page
=
browser
.
newPage
();
page
.
setDefaultTimeout
(
timeout
);
page
.
setDefaultTimeout
(
timeout
);
page
.
goTo
(
url
,
false
);
page
.
goTo
(
url
,
false
);
...
@@ -47,19 +53,15 @@ public class BrowserController {
...
@@ -47,19 +53,15 @@ public class BrowserController {
WaitForSelectorOptions
waitForSelectorOptions
=
new
WaitForSelectorOptions
();
WaitForSelectorOptions
waitForSelectorOptions
=
new
WaitForSelectorOptions
();
waitForSelectorOptions
.
setTimeout
(
timeout
);
waitForSelectorOptions
.
setTimeout
(
timeout
);
waitForSelectorOptions
.
setVisible
(
Boolean
.
TRUE
);
waitForSelectorOptions
.
setVisible
(
Boolean
.
TRUE
);
ElementHandle
elementHandle
=
page
.
waitForSelector
(
StringUtils
.
isNotEmpty
(
selector
)
?
selector
:
"selector"
,
waitForSelectorOptions
);
ElementHandle
elementHandle
=
page
.
waitForSelector
(
selector
,
waitForSelectorOptions
);
ScreenshotOptions
screenshotOptions
=
new
ScreenshotOptions
();
ScreenshotOptions
screenshotOptions
=
new
ScreenshotOptions
();
screenshotOptions
.
setType
(
MediaType
.
IMAGE_JPEG
.
getSubtype
());
screenshotOptions
.
setType
(
MediaType
.
IMAGE_JPEG
.
getSubtype
());
screenshotOptions
.
setQuality
(
quality
!=
null
?
quality
:
80
);
screenshotOptions
.
setQuality
(
quality
);
//设置截图范围
//设置截图范围
screenshotOptions
.
setFullPage
(
Boolean
.
TRUE
);
screenshotOptions
.
setFullPage
(
Boolean
.
TRUE
);
if
(
StringUtils
.
isNullOrEmpty
(
filename
))
{
filename
=
SnowFlake
.
nextSerialNumber
();
}
//screenshotOptions.setPath(filename + ".jpg");
//screenshotOptions.setPath(filename + ".jpg");
String
base64Str
=
page
.
screenshot
(
screenshotOptions
);
String
base64Str
=
page
.
screenshot
(
screenshotOptions
);
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment