I am trying to parse some HTML files. I want to extract all text using a specific font size. For instance, I want to get all text of p, div, span, etc tags using font-size:10px in their style. I am using BeautifulSoup to parse my HTML files and extract the preferred data. To extract data of tags using specific font sizes, I used the following script in python. While it does not work.
file = open("file.html", "r")
soup = BeautifulSoup(file.read(), features="html.parser")
main_texts = soup.findAll(attrs={"style":"font-size:10px"})
for item in main_texts :
whole_text += item.getText()
Also, My HTML content is like this
<span style="font-family: TimesNewRomanPSMT; font-size:10px"> </span><span style="font-family: ABCDEE+Calibri-Bold; font-size:11px"> </span><span style="font-family: TimesNewRomanPSMT; font-size:14px">Academic Qualifications <span style="position:absolute; border: black 1px solid; left:36px; top:143px; width:159px; height:0px;"></span>
</span><span style="font-family: TimesNewRomanPSMT; font-size:10px">2012-Current CPA (Australia) CPA (Aust.) Holder </span><span style="font-family: TimesNewRomanPSMT; font-size:14px"> </span><span style="font-family: TimesNewRomanPSMT; font-size:10px">2010-2012 Royal Melbourne Institute of Technology Bachelor in Business (Accountancy) 2006-2009 Ngee Ann Polytechnic Diploma in Accountancy 2002-2005 Henderson Secondary School GCE ‘O’ Levels 1996-2001 River Valley Primary School </span><span style="font-family: TimesNewRomanPSMT; font-size:10px"> PSLE </span><span style="font-family: ABCDEE+Calibri; font-size:15px"> Co-Curriculum Achievements <span style="position:absolute; border: black 1px solid; left:36px; top:399px; width:189px; height:1px;"></span>
</span><span style="font-family: TimesNewRomanPSMT; font-size:10px">NPCC (2002 -2005) -National Youth Achievement Award (Bronze) -CCA Merit Award (NPCC) Ngee Ann Poly (2006 – 2009) -Freshmen Orientation Sub-Committee Member -Freshmen Recruitment Sub-Committee Member -Ngee Ann Canoeing Club Member </span><span style="font-family: ABCDEE+Cambria; font-size:12px"> Nippon Yusen Kaisha (2011- 2012) - Social Recreational Committee Member </span><span style="font-family: ABCDEE+Calibri; font-size:15px"> Personal Skills <span style="position:absolute; border: black 1px solid; left:36px; top:549px; width:91px; height:1px;"></span>
</span><span style="font-family: TimesNewRomanPS-BoldMT; font-size:10px">Software Skills </span><span style="font-family: TimesNewRomanPSMT; font-size:10px">1.</span><span style="font-family: ArialMT; font-size:11px"> </span><span style="font-family: TimesNewRomanPSMT; font-size:10px">Microsoft Office (Excel, Pivot, V-lookup, Powerpoint) Excellent </span><span style="font-family: TimesNewRomanPSMT; font-size:10px">2.</span><span style="font-family: ArialMT; font-size:11px"> </span><span style="font-family: TimesNewRomanPSMT; font-size:10px">Bloomberg Intermediate </span><span style="font-family: TimesNewRomanPSMT; font-size:10px">3.</span><span style="font-family: ArialMT; font-size:11px"> </span><span style="font-family: TimesNewRomanPSMT; font-size:10px">Thomson Reuters Intermediate 4.</span>
Do you have any idea to resolve this problem?