Selecting all elements that meet a criteria using selenium (python)
<p>Using selenium, is there a way to have the script pick out elements that meet a certain criteria? </p>

<p>What I'm exactly trying to do is have selenium select all Twitch channels that have more than X viewers. If you inspect element, you find this: </p>

<pre><code>&lt;p class="info"
    562
    viewers on
    &lt;a class="js-profile-link" href="/hey_jase/profile" 
    data-tt_content="live_channel" data-tt_content_index="1"
    data-tt_medium="twitch_directory" data-ember-action="1471"&gt;
    Hey_Jase
    &lt;/a&gt;
&lt;/p&gt;
</code></pre>

<p>First of all, you can find all twitch channel links. Then, filter them based on the view count.</p>

<p>Something along these lines:</p>

<pre><code>import re
from selenium import webdriver


THRESHOLD = 100  

driver = webdriver.Firefox()
driver.get("url")

pattern = re.compile(r"(\d+)\s+viewers on")
for link in driver.find_elements_by_css_selector("p.info a[data-tt_content=live_channel]"):
    text = link.find_element_by_xpath("..").text  # get to the p parent element
    match = pattern.search(text)  # extract viewers count
    if match:
        viewers_count = int(match.group(1))
        if viewers_count &gt;= THRESHOLD:
            print(link.text, viewers_count)
</code></pre>

python selenium selenium-webdriver