How do I make selenium click on elements and scrape data before the page has fully loaded? My internet connection is quite terrible so it sometimes takes forever to load the page entirely, is there anyway around this?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
ChromeDriver 77.0 (which supports Chrome version 77) now supports
eager
as pageLoadStrategy.As you question mentions of
click on elements and scrape data before the page has fully loaded
in this case we can take help of an attributepageLoadStrategy
. When Selenium loads a page/url by default it follows a default configuration withpageLoadStrategy
set tonormal
. Selenium can start executing the next line of code from differentDocument readiness state
. Currently Selenium supports 3 differentDocument readiness state
which we can configure through thepageLoadStrategy
as follows:none
(undefined)eager
(page becomes interactive)normal
(complete page load)Here is the code block to configure the
pageLoadStrategy
:For Chromedriver it works the same as in @DebanjanB's answer, however the 'eager' page load strategy is not yet supported
So for chromedriver you get:
Note that when using the 'none' strategy you most likely have to implement your own wait method to check if the element you need is loaded.
Now you can start interacting with your element before the page is fully loaded!