简体   繁体   English

与硒多线程find_element

[英]multithreading find_element with selenium

I'm trying to lower execution time by multithreading the more time consuming parts of my script, which is mostly the locator calls. 我试图通过多线程脚本中耗时更多的部分(主要是定位器调用)来减少执行时间。

However, I keep getting "CannotSendRequest" and "ResponseNotReady" exceptions from the two threads. 但是,我不断从两个线程获取“ CannotSendRequest”和“ ResponseNotReady”异常。

Is this because I'm using the same http handle? 这是因为我使用了相同的http句柄吗?

input_worker = threading.Thread(name="input_worker", target=find_input_fields, args=(form, args, logger))
input_worker.setDaemon(True)
select_worker = threading.Thread(name="select_worker", target=find_select_fields, args=(form, logger))
select_worker.setDaemon(True)

thread_pool.append(input_worker)
thread_pool.append(select_worker)

And in the find_input_fields function is something like 在find_input_fields函数中,类似

input_fields = form.find_elements_by_tag_name("input")

Selenium takes 1 cpu core per thread. 硒每个线程占用1个cpu内核。 And multi threading is not suggested for Selenium webdriver. Selenium Webdriver不建议使用多线程。 Consider If you have a 4 core system you can run 4 selenium separate thread linked to each core. 考虑如果您有一个4核心系统,则可以运行4个与每个核心链接的硒独立线程。 As you are creating 2 threads you are getting Exceptions from the two threads. 当您创建2个线程时,您将从这两个线程中获取异常。

FYI 费耶

Is it possible to parallelize selenium webdriver get_attribute calls in python? 是否可以在python中并行化Selenium Webdriver get_attribute调用?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM