Selenium webdriver using thread pool. (Chrome only now.)
Project description
threadingwebdriver
Selenium webdriver using two threadpools. (Available chrome only now.)
ThreadPool(1) for control browser.
ThreadPool(custom_number) for read page(get WebElement).
Initialize
import threadingwebdriver
driver = threadingwebdriver.ChromeWebdriver()
driver.initialize()
Close
Close driver. It will wait tasks of ThreadPools are finish.
driver.close()
Open URL (Async)
url = 'https://www.google.com/'
driver.open_async(url)
Open URL (Sync)
url = 'https://www.google.com/'
is_open:bool = driver.open(3, url)
Get Element (Async)
url = 'https://www.google.com/'
driver.open_async(url)
timeout = 3
body_xpath = '/html/body'
body_xpath_result:WebElementAsyncResult = driver.get_element_xpath_async(timeout, body_xpath)
# code...
body:WebElement = body_xpath_result.get()
Concurrency
import threadingwebdriver
driver = threadingwebdriver.ChromeWebdriver()
driver.initialize(read_thread_count = 3)
timeout = 2
url = "Input Your URL"
driver.open(timeout, url)
p_async = driver.get_element_xpath_async(timeout, '/html/body/div/p')
a_async = driver.get_element_xpath_async(timeout, '/html/body/div/a')
div_async = driver.get_element_xpath_async(timeout, '/html/body/div')
p = p_async.get()
a = a_async.get()
div = div_async.get()
Get Element (Sync)
timeout = 3
body_xpath = '/html/body'
body:WebElement = driver.get_element_xpath(timeout, body_xpath)
Exceptions
Based on thread priority.
url1 = 'https://www.google.com/'
url2 = 'https://www.github.com/'
driver.open_async(url1)
driver.open_async(url2)
timeout = 3
body_xpath = '/html/body'
body_xpath_result:WebElementAsyncResult = driver.get_element_xpath_async(timeout, body_xpath)
# Exception: if run 'get_element_xpath_async()' before run 'open_async(url2)'.
url1 = 'https://www.google.com/'
url2 = 'https://www.github.com/'
driver.open_async(url1)
timeout = 3
body_xpath = '/html/body'
body_xpath_result:WebElementAsyncResult = driver.get_element_xpath_async(timeout, body_xpath)
driver.open_async(url2) # Exception: run 'open_async(url2)' when not finish 'get_element_xpath_async()'.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for threadingwebdriver-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74cee17217110ecbd5a3dea7f95291dc3d93ce6ceeb14edce11074e5e48127f9 |
|
MD5 | 44e4d5141b736b99f9dc13ad05386bf0 |
|
BLAKE2b-256 | a4b03e09246c3eae9e0ab1bac837d4cd72ac0755f305025bbcce90648e429c69 |