-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatch_undetected.py
30 lines (26 loc) · 937 Bytes
/
patch_undetected.py
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
# patch_undetected.py
import re
from pathlib import Path
import undetected_chromedriver
def patch_undetected():
"""
Instead of rewriting the file (which can cause permission errors),
we patch the module in memory by overriding the LooseVersion attribute.
"""
try:
import undetected_chromedriver.patcher as patcher
from packaging.version import Version as LooseVersion
patcher.LooseVersion = LooseVersion
print("Patched undetected_chromedriver.patcher in memory to use packaging.version.")
except Exception as e:
print("Error patching undetected_chromedriver in memory:", e)
def patch_setuptools():
import importlib.util
spec = importlib.util.find_spec("setuptools")
if spec is None:
print("Warning: setuptools module not found.")
else:
print("setuptools found.")
if __name__ == "__main__":
patch_setuptools()
patch_undetected()