抓取网页时触发onmouseover事件的最快方法是什么?
所以我想将鼠标移到div元素上,然后调用javascript函数来更新另一个div(显示我要抓取的工具提示)。当将鼠标移离第一个div时,工具提示会消失,但仍可以进行抓取,因为只有显示样式设置为无。 我想使此过程尽快完成。
当前,我使用Selenium和move_to_element大约需要0.55s。这很长,因为我最终必须重复此过程> 60次。
start_time = time.time()
action = actionChains(driver)
action.move_to_element(box)
action.perform()
print("Time: ",time.time() - start_time()) # ~0.5s
当我在scrapy shell中使用它时,我看到此硒请求显示以下消息。
[selenium.webdriver.remote.remote_connection] DEBUG: POST http://127.0.0.1:57309/session/49aea696ad5c6a23dd1a292adacf1d92/actions {"actions": [{"parameters": {"pointerType": "mouse"},"type": "pointer","id": "mouse","actions": [{"duration": 250,"x": 0,"type": "pointerMove","y": 0,"origin": {"element-6066-11e4-a52e-4f735466cecf": "63f7afad-d9d6-49c2-989a-75c6d083c055"}}]},{"type": "key","id": "key","actions": [{"duration": 0,"type": "pause"}]}]}
在“动作”中显示为“持续时间:250”,我怀疑这是move_to_element动作的持续时间。我找不到任何方法来手动减少此持续时间,这可能吗? 我还听说scrapy-splash比硒快得多,但尚未找到很多使用方法。它也可以模拟悬停事件,还是可以使用正确的参数直接调用javascript函数?