Skip to content

Commit 8caed4f

Browse files
committed
[feature] #43 local file url support added
1 parent b14594b commit 8caed4f

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

s_tool/utils.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,25 @@ def get_session(driver: webdriver) -> str:
2222
return driver.session_id
2323

2424

25+
def is_local(path: str) -> str:
26+
"""Return valid URL path for file
27+
28+
Args:
29+
path (str): normal path or URL
30+
31+
Returns:
32+
str: Modified file path if local file
33+
Returns path as it is if URL
34+
"""
35+
import os
36+
37+
URL = path
38+
if os.path.exists(path) or path.startswith("file"):
39+
if not URL.startswith("file"):
40+
URL = f"file://{URL}"
41+
return URL
42+
43+
2544
def visit(driver: webdriver, url: str) -> None:
2645
"""Visit given url
2746
@@ -32,7 +51,7 @@ def visit(driver: webdriver, url: str) -> None:
3251
Returns:
3352
None
3453
"""
35-
driver.get(url)
54+
driver.get(is_local(url))
3655

3756

3857
def page_source(driver: webdriver) -> str:

0 commit comments

Comments
 (0)