FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
lambda-selenium/lambda_function.py at main · teticio/lambda-selenium · GitHub
teticio
/
lambda-selenium
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
11
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
lambda-selenium
/
lambda_function.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
69 lines (55 loc) · 2.16 KB
Breadcrumbs
lambda-selenium
/
lambda_function.py
Copy path
File metadata and controls
69 lines (55 loc) · 2.16 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import
importlib
.
util
import
logging
import
os
import
shutil
import
subprocess
import
unittest
.
mock
as
mock
from
tempfile
import
NamedTemporaryFile
,
gettempdir
with
mock
.
patch
(
"multiprocessing.Lock"
,
return_value
=
object
()):
import
undetected_chromedriver
as
uc
logger
=
logging
.
getLogger
()
logger
.
setLevel
(
logging
.
DEBUG
)
tempdir
=
gettempdir
()
def
get_driver
()
->
uc
.
Chrome
:
options
:
uc
.
ChromeOptions
=
uc
.
ChromeOptions
()
options
.
add_argument
(
"--headless"
)
options
.
add_argument
(
"--disable-gpu"
)
options
.
add_argument
(
"--disable-dev-shm-usage"
)
options
.
add_argument
(
"--hide-scrollbars"
)
options
.
add_argument
(
"--single-process"
)
options
.
add_argument
(
"--ignore-certificate-errors"
)
options
.
add_argument
(
f"--homedir=
{
tempdir
}
"
)
options
.
add_argument
(
f"--disk-cache-dir=
{
tempdir
}
/cache-dir"
)
options
.
add_argument
(
f"--data-path=
{
tempdir
}
/data-path"
)
options
.
add_experimental_option
(
"prefs"
, {
"download.default_directory"
:
tempdir
})
logger
.
debug
(
"Opening driver"
)
result
=
subprocess
.
run
(
[
"google-chrome"
,
"--version"
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
text
=
True
,
)
logger
.
debug
(
f"Chrome version:
{
result
.
stdout
}
"
)
chrome_version
=
int
(
result
.
stdout
.
split
(
" "
)[
-
2
].
split
(
"."
)[
0
])
return
uc
.
Chrome
(
options
=
options
,
version_main
=
chrome_version
)
def
lambda_handler
(
event
,
context
):
# pylint: disable=unused-argument
src
=
event
.
pop
(
"src"
)
if
not
src
:
return
{
"statusCode"
:
400
,
"body"
:
"Missing src parameter"
}
with
NamedTemporaryFile
(
mode
=
"w"
,
suffix
=
".py"
)
as
temp
:
temp
.
write
(
src
)
temp
.
flush
()
spec
=
importlib
.
util
.
spec_from_file_location
(
"module.name"
,
temp
.
name
)
module
=
importlib
.
util
.
module_from_spec
(
spec
)
spec
.
loader
.
exec_module
(
module
)
if
not
hasattr
(
module
,
"main"
):
return
{
"statusCode"
:
400
,
"body"
:
"Missing main function"
,
}
driver
=
get_driver
()
result
=
module
.
main
(
driver
,
**
event
)
driver
.
close
()
shutil
.
rmtree
(
tempdir
,
ignore_errors
=
True
)
os
.
makedirs
(
tempdir
,
exist_ok
=
True
)
return
{
"statusCode"
:
200
,
"body"
:
str
(
result
)}
Back
|
FazBrowse Home
|
New Git URL