Aug-11-2017, 03:28 AM
Got you. Thanks Do you think we can improve the code little better. I do not want list comprehension as it is confusing :)
appPath = 'D:\\Backup\\Drive_D\\W0rk\\Script\\Python\\HTMLTOCSV_Python\\Try\\' cols=[] newcols=[] from bs4 import BeautifulSoup import os soup = BeautifulSoup(open(appPath+'Cust\\consolidated_report_201708100600Copy.html','rb'), 'lxml') h1 = soup.find_all("h1") for col in h1: cols.append(col.get_text()) for item in cols: technology = item.split(':')[0] color = item.split(':')[-1] if color in ["red","yellow"]: newcols.append((technology,color)) newcols.sort(reverse=True) newcols = dict(newcols) print(newcols)