I've searched but couldn't find the right answer, maybe my search query is not correct. But as for the question, I have below in html document for dropdown values.
<select style="background: red; color: #fff; padding: 5px;" class="mainNewcat" size="1">
<option>My New List</option>
<option value="http://www.google.com/value1.html">Value 1</option><option value="http://www.google.com/value2.html">Value 2</option><option value="http://www.google.com/value3.html">Value 3</option> </select>
<select style="background: green; color: #fff; padding: 5px;" class="mainOldcat" size="1">
<option>My Old List</option>
<option value="http://www.yahoo.com/cat1.html">Category 1</option><option value="http://www.yahoo.com/cat2.html">Category 2</option><option value="http://www.yahoo.com/cat3.html">Category 3</option> </select>
What i'm looking for is url and text from only 'My New List'. So far regex solution I have is to first search for option value block within 'My New List', and then another regex to search for url and text from first result, like below which is using python's RE module.
main_regex = re.compile('<select.+?\n.+?New.+?\n(.+?)<\/select>').findall(html)
final_regex = re.compile('value="(.+?)">(.+?)</option>').findall(main_regex)
Is there a better solution than what I have? or should I use some parser instead of regex?