from bs4 import BeautifulSoup
html = '''<tbody id="plaintiff-body">
<tr>
<td><img id="plaimg0001" src="/CaseInformationOnline/images/minus.png" onclick="showhide('pladetail0001','','plaimg0001')"></td>
<td>JENEE BENNETT</td>
<td></td>
<td>COURTNEY L HANNA</td>
</tr>
<tr id="pladetail0001" style="" valign="top">
<td></td>
<td>2348 WOODBROOK CIR N<br>UNIT D<br>COLUMBUS, OH 43223</td>
<td></td>
<td>JOSEPH & JOSEPH CO LPA <br>SUITE 200<br>155 W MAIN ST<br>COLUMBUS, OH 43215<br>(614) 449-8282<br><br>DEBORAH L MCNINCH<br>JOSEPH & JOSEPH CO LPA <br>THE WATERFORD, SUITE 200 <br>155 W MAIN ST<br>COLUMBUS, OH 43215<br>(614) 449-8282<br><br>S K DODDERER<br>155 W MAIN STREET<br>#200<br>COLUMBUS, OH 43215<br>(614) 449-8282</td>
</tr>
</tbody>'''
soup = BeautifulSoup(html, 'lxml')
att = [x.get_text(strip=True, separator=' ') for x in soup.select(
'#plaintiff-body tr:first-child > td:nth-child(4), #plaintiff-body tr:nth-child(2) > td:last-child')]
print(att)
Current output:
['COURTNEY L HANNA', 'JOSEPH & JOSEPH CO LPA SUITE 200 155 W MAIN ST COLUMBUS, OH 43215 (614) 449-8282 DEBORAH L MCNINCH JOSEPH & JOSEPH CO LPA THE WATERFORD, SUITE 200 155 W MAIN ST COLUMBUS, OH 43215 (614) 449-8282 S K DODDERER 155 W MAIN STREET #200 COLUMBUS, OH 43215 (614) 449-8282']
Desired Output:
['COURTNEY L HANNA', 'JOSEPH & JOSEPH CO LPA SUITE 200 155 W MAIN ST COLUMBUS, OH 43215 (614) 449-8282']
How to achieve that ?
I'm thinking to use https://www.crummy.com/software/BeautifulSoup/bs4/doc/#a-function to pass a function and loop overn the match and once i found br empty then i will stop the loop.
Otherwise i can get x itself instead of x.get_text() and then split on >< to get the first index and then use https://w3lib.readthedocs.io/en/latest/w3lib.html?highlight=remove#w3lib.html.remove_tags
Happy to know if there a direct solution with CSS or a simple one.