Issue
Hello guys i get this code in beautiful soup
<div class="user_info_right d-flex">
<div class="info_one col" style="background-color: black">
<h2>INFO</h2>
<table class="table_transparen">
<tbody>
<tr>
<th>Country/State</th>
<td>Tennessee</td>
</tr>
<tr>
<th>City</th>
<td>Nashville</td>
</tr>
<tr>
<th>Address</th>
<td>Nashville , Tennessee</td>
</tr> <tr>
<th>Category</th>
<td> <a href="/region_9/country_19/city_1241">Smash</a>
</td>
</tr>
<tr>
<th>Hours</th>
I need to get Nashville , Tennessee but sometime the field " Address Nashville , Tennessee doesn't exist ! So i can't just find data between City and Category
So my question if how i can check if Address exist or not ?
Thank you so much
Solution
You need just to check if there is a th tag with Address as its text node, if this not the case find() will return None. ( the code below is self explanatory ;) )
address_th = soup.find("th",string="Address")
print(address_th)
if address_th is not None:
address_value = address_th.find_next_sibling().text
print(address_value)
Answered By - Ktifler
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.