Problem statement:
Make country wise player list from the following html code
HTML CODE:
<ul>
<li>
Australia
<ol>
<li>Steven Smith</li>
<li>David Warner</li>
</ol>
</li>
<li>
Bangladesh
<ol>
<li>Mashrafe Mortaza</li>
<li>Tamim Iqbal</li>
</ol>
</li>
<li>
England
<ol>
<li>Eoin Morgan</li>
<li>Jos Buttler</li>
</ol>
</li>
</ul>
Expected Output:
Australia- Steven Smith, David Warner
Bangladesh- Mashrafe Mortaza, Tamim Iqbal
England- Eoin Morgan, Jos Buttler
My Code:
import re
with open('playerlist.html', 'r') as f:
text = f.read()
mytext = re.sub(r'[\n\t]', '', text)
pat = r'<li>(\w+?)<ol><li>(\w+\s?\w+)</li><li>(\w+\s?\w+)</li>'
cpat = re.compile(pat)
result = cpat.findall(mytext)
for a,b,c in result:
print('{0}- {1}, {2}'.format(a,b,c))