3.0.4
This commit is contained in:
parent
77a3c3020f
commit
ec49c0086b
25
README.md
25
README.md
|
@ -20,6 +20,18 @@ Automatically downloads the driver binary and patches it.
|
||||||
|
|
||||||
- todo: work towards asyncification and selenium 4
|
- todo: work towards asyncification and selenium 4
|
||||||
|
|
||||||
|
#### words of wisdom: ####
|
||||||
|
Whenever you encounter the daunted
|
||||||
|
|
||||||
|
```from session not created: This version of ChromeDriver only supports Chrome version 96 # or what ever version```
|
||||||
|
|
||||||
|
the solution is simple:
|
||||||
|
```python
|
||||||
|
import undetected_chromedriver.v2 as uc
|
||||||
|
driver = uc.Chrome(version_main=95)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
**July 2021: Currently busy implementing selenium 4 for undetected-chromedriver**
|
**July 2021: Currently busy implementing selenium 4 for undetected-chromedriver**
|
||||||
|
|
||||||
|
@ -44,8 +56,7 @@ This is also the snippet i recommend using in case you experience an issue.
|
||||||
```python
|
```python
|
||||||
import undetected_chromedriver.v2 as uc
|
import undetected_chromedriver.v2 as uc
|
||||||
driver = uc.Chrome()
|
driver = uc.Chrome()
|
||||||
with driver:
|
driver.get('https://nowsecure.nl') # known url using cloudflare's "under attack mode"
|
||||||
driver.get('https://nowsecure.nl') # known url using cloudflare's "under attack mode"
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### The Version 2 more advanced way, including setting profie folder ###
|
### The Version 2 more advanced way, including setting profie folder ###
|
||||||
|
@ -66,10 +77,9 @@ options.add_argument('--user-data-dir=c:\\temp\\profile2')
|
||||||
|
|
||||||
# just some options passing in to skip annoying popups
|
# just some options passing in to skip annoying popups
|
||||||
options.add_argument('--no-first-run --no-service-autorun --password-store=basic')
|
options.add_argument('--no-first-run --no-service-autorun --password-store=basic')
|
||||||
driver = uc.Chrome(options=options)
|
driver = uc.Chrome(options=options, version_main=94) # version_main allows to specify your chrome version instead of following chrome global version
|
||||||
|
|
||||||
with driver:
|
driver.get('https://nowsecure.nl') # known url using cloudflare's "under attack mode"
|
||||||
driver.get('https://nowsecure.nl') # known url using cloudflare's "under attack mode"
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -86,7 +96,7 @@ However i implemented my own for now. Since i needed it myself for investigation
|
||||||
import undetected_chromedriver.v2 as uc
|
import undetected_chromedriver.v2 as uc
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
|
|
||||||
driver = uc.Chrome(enable_cdp_event=True)
|
driver = uc.Chrome(enable_cdp_events=True)
|
||||||
|
|
||||||
def mylousyprintfunction(eventdata):
|
def mylousyprintfunction(eventdata):
|
||||||
print(pformat(eventdata))
|
print(pformat(eventdata))
|
||||||
|
@ -112,8 +122,7 @@ driver.add_cdp_listener('Network.dataReceived', mylousyprintfunction)
|
||||||
|
|
||||||
# now all these events will be printed in my console
|
# now all these events will be printed in my console
|
||||||
|
|
||||||
with driver:
|
driver.get('https://nowsecure.nl')
|
||||||
driver.get('https://nowsecure.nl')
|
|
||||||
|
|
||||||
|
|
||||||
{'method': 'Network.requestWillBeSent',
|
{'method': 'Network.requestWillBeSent',
|
||||||
|
|
|
@ -65,7 +65,7 @@ def _cleanup():
|
||||||
logging.getLogger(__name__).debug('cleaning up pid %d ' % pid)
|
logging.getLogger(__name__).debug('cleaning up pid %d ' % pid)
|
||||||
os.kill(pid, signal.SIGTERM)
|
os.kill(pid, signal.SIGTERM)
|
||||||
except: # noqa
|
except: # noqa
|
||||||
traceback.print_exc()
|
pass
|
||||||
|
|
||||||
|
|
||||||
atexit.register(_cleanup)
|
atexit.register(_cleanup)
|
||||||
|
|
|
@ -12,6 +12,7 @@ import shutil
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
|
import inspect
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import selenium.webdriver.chrome.service
|
import selenium.webdriver.chrome.service
|
||||||
|
@ -646,6 +647,15 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
|
||||||
self.quit()
|
self.quit()
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
|
try:
|
||||||
|
curframe = inspect.currentframe()
|
||||||
|
callframe = inspect.getouterframes(curframe, 2)
|
||||||
|
caller = callframe[1][3]
|
||||||
|
logging.getLogger(__name__).debug('__enter__ caller: %s' % caller)
|
||||||
|
if caller == 'get':
|
||||||
|
return
|
||||||
|
except (AttributeError, ValueError, KeyError, OSError) as e:
|
||||||
|
logging.getLogger(__name__).debug(e)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||||
|
|
Loading…
Reference in New Issue