As an example, the chat site Omegle always displays on its homepage the current number of users online, which I am able to 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 is like:
22,183
This number is dynamically generated and updated periodically by a script, and I want to read just this dynamically updated content at intervals without repeatedly loading the entire page with driver.get
. What Selenium Webdriver method or functionality will let me do that?
This article seems like a relevant lead, though it led me nowehere.
This is untested, 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 if you find the element after it's been altered, it will give you the new value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With