У меня проблемы с удалением идентификаторов html из приведенного ниже файла html, потому что есть две строки кода, у которых нет идентификатора под 14 Jun 2020
, что означает, что после назначения слотов больше нет 8.15am on 14 June
, встречи возобновляются 15 июня.
<table class="table table-borderless table-striped no-background clear-padding-first-child available-slots-mobile main-table clone">
<thead>
<tr>
<th width="14%" class="text-left nowrap fixed-side">Session Date</th>
<th width="14%" class="text-center">
<b>1</b>
</th>
<th width="14%" class="text-center">
<b>2</b>
</tr>
</thead>
<tbody class="tr-border-bottom">
<tr>
<th class="pb-15 text-left fixed-side">
<a href="javascript:changeDate('13 Jun 2020');">13 Jun 2020</a>
<br> Saturday
</th>
<td class="pb-15 text-center">
<a href="#" id="1217464_1_13/6/2020 12:00:00 AM" class="slotBooking">
8:15 AM ✔
</a>
</td>
</tr>
<tr>
<th class="pb-15 text-left fixed-side">
<a href="javascript:changeDate('14 Jun 2020');">13 Jun 2020</a>
<br> Sunday
</th>
<td class="pb-15 text-center">
<a href="#" id="1217482_1_14/6/2020 12:00:00 AM" class="slotBooking">
8:15 AM ✔
</a>
</td>
<td class="pb-15 text-center"><span class="c-gray">n/a</span></td>
<td class="pb-15 text-center"><span class="c-gray">n/a</span></td>
</tr>
<tr>
<th class="pb-15 text-left fixed-side">
<a href="javascript:changeDate('15 Jun 2020');">15 Jun 2020</a>
<br> Monday
</th>
<td class="pb-15 text-center">
<a href="#" id="1217506_1_15/6/2020 12:00:00 AM" class="slotBooking">
8:15 AM ✔
</a>
</td>
</tr>
</tbody>
</table>
Я пришел с приведенным ниже кодом, но будут напечатаны только html идентификаторы встреч до 8.15am 14th June 2020 slot
. Затем я сталкиваюсь с TypeError (объект NoneType не повторяется) после того, как был напечатан идентификатор слота 8.15am 14 June
, и не напечатаны идентификаторы слотов 15 июня.
for slots in soup.findAll(attrs={"class" : "pb-15 text-center"}):
tags = slots.find("a")
for IDS in tags:
IDS = tags.attrs["id"]
print (IDS)
Я также попытался обработать исключение здесь, но я столкнулся с синтаксической ошибкой (и я не слишком уверен, что именно я сделал неправильно).
for slots in soup.findAll(attrs={"class" : "pb-15 text-center"}):
tags = slots.find("a")
for IDS in tags:
try:
IDS = tags.attrs["id"]
except TypeError:
else:
print (IDS)