Use Selenium Webdriver to receive periodically updated content.

As an example, the Omegle chat site always displays on its homepage the current number of Internet users that I can extract with this python script using the headless HTMLUnit Webdriver in Selenium:

 from selenium import webdriver driver = webdriver.Remote(desired_capabilities=webdriver.DesiredCapabilities.HTMLUNITWITHJS) driver.get('http://www.omegle.com/') element = driver.find_element_by_id("onlinecount") print element.text.split()[0] 

The output looks like this:

 22,183 

This number is dynamically generated and updated periodically with a script, and I want to read this dynamically updated content at intervals without reloading the entire page using driver.get . What method or functionality of Selenium Webdriver will allow me to do this?

This article seems relevant, although it has led me to the future.

+6
source share
1 answer

This has not been verified, but I think the following might work:

 from selenium import webdriver from time import sleep driver = webdriver.Remote(desired_capabilities=webdriver.DesiredCapabilities.HTMLUNITWITHJS) driver.get('http://www.omegle.com/') interval = 10 #or whatever interval you want while True: element = driver.find_element_by_id("onlinecount") print element.text.split()[0] sleep(interval) 

I think that if you find an element after changing it, it will give you a new meaning.

+7
source

All Articles