Webdriver find elements by regex in python
<p>I am trying to extract all those tags whose class name fits the regex pattern frag-0-0, frag-1-0, etc. from <a href="http://de.vroniplag.wikia.com/wiki/Aak/002" rel="nofollow">this link</a></p>

<p>I am trying to retrieve it using the following code</p>

<pre><code>    driver = webdriver.Chrome(chromedriver)
    for frg in frgs:
        driver.get(URL + frg[1:])
        frags=driver.find_elements_by_id(re.compile('frag-[0-9]-0'))
    for frag in frags:
            for tag in frag.find_elements_by_css_selector('[class^=fragmark]'):
                lst.append([tag.get_attribute('class'), tag.text])
    driver.quit()
    return lst
</code></pre>

<p>But I get an error. What is the right way of doing this?</p>

<p>The error is as follows:</p>

<pre><code>Traceback (most recent call last):
  File "vroni.py", line 119, in &lt;module&gt;
    op('Aaf')
  File "vroni.py", line 104, in op
    plags=getplags(cd)
  File "vroni.py", line 95, in getplags
    frags=driver.find_elements_by_id(re.compile('frag-[0-9]-0'))
  File "/home/eadaradhiraj/Documents/webscrape/venv/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 281, in find_elements_by_id
    return self.find_elements(by=By.ID, value=id_)
  File "/home/eadaradhiraj/Documents/webscrape/venv/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 778, in find_elements
    'value': value})['value']
  File "/home/eadaradhiraj/Documents/webscrape/venv/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 234, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/home/eadaradhiraj/Documents/webscrape/venv/local/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 398, in execute
    data = utils.dump_json(params)
  File "/home/eadaradhiraj/Documents/webscrape/venv/local/lib/python2.7/site-packages/selenium/webdriver/remote/utils.py", line 34, in dump_json
    return json.dumps(json_struct)
  File "/usr/lib/python2.7/json/__init__.py", line 243, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python2.7/json/encoder.py", line 207, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python2.7/json/encoder.py", line 270, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python2.7/json/encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: &lt;_sre.SRE_Pattern object at 0xb668b1b0&gt; is not JSON serializable
</code></pre>