Я сделал запрос к API и в итоге получил следующее:
<!--START OF OUTPUT FROM EXCEL PUBLISH AS WEB PAGE WIZARD -->
<!----------------------------->
<div align="center" id="Storage Report HTML Generator_25382" x:publishsource="Excel">
<table width="1269" style="width: 951pt; border-collapse: collapse; table-layout: fixed;" border="0" cellspacing="0" cellpadding="0">
<colgroup><col width="185" style="width: 139pt; mso-width-source: userset; mso-width-alt: 6570;">
<col width="91" style="width: 68pt; mso-width-source: userset; mso-width-alt: 3242;">
<col width="106" style="width: 79pt; mso-width-source: userset; mso-width-alt: 3754;">
<col width="94" style="width: 70pt; mso-width-source: userset; mso-width-alt: 3328;">
<col width="150" style="width: 113pt; mso-width-source: userset; mso-width-alt: 5347;">
<col width="195" style="width: 146pt; mso-width-source: userset; mso-width-alt: 6940;">
<col width="64" style="width: 48pt;" span="7">
</colgroup><tbody><tr height="21" style="height: 15.6pt;">
<td width="276" height="21" class="xl9825382" style="width: 207pt; height: 15.6pt;" colspan="2">Energy Information Administration</td>
<td width="106" class="xl9925382" style="width: 79pt;"></td>
<td width="94" class="xl9925382" style="width: 70pt;"></td>
<td width="150" class="xl6725382" style="width: 113pt;"></td>
<td width="195" class="xl6725382" style="width: 146pt;"></td>
<td width="64" class="xl1525382" style="width: 48pt;"></td>
<td width="64" class="xl1525382" style="width: 48pt;"></td>
<td width="64" class="xl1525382" style="width: 48pt;"></td>
<td width="64" class="xl1525382" style="width: 48pt;"></td>
<td width="64" class="xl1525382" style="width: 48pt;"></td>
<td width="64" class="xl1525382" style="width: 48pt;"></td>
<td width="64" class="xl1525382" style="width: 48pt;"></td>
</tr>
Это всего лишь фрагмент, очевидно, эта часть страницы была сгенерирована с помощью Excel, поэтому она не форматируется должным образом (во всяком случае, чтобы избежать получения этой информации с запросами в правильном HTML формате, также приветствуется)
Я просто заменил <
и >
на <
и <
соответственно на all_data_html = all_data_html.replace("<", "<").replace(">", ">").replace(";", ">")
. Что на самом деле делает его чистым:
<!----------------------------->
<!--START OF OUTPUT FROM EXCEL PUBLISH AS WEB PAGE WIZARD -->
<!----------------------------->
<div align="center" id="Storage Report HTML Generator_25382" x:publishsource="Excel">
<table width="1269" style="width: 951pt; border-collapse: collapse; table-layout: fixed;" border="0" cellspacing="0" cellpadding="0">
<colgroup><col width="185" style="width: 139pt; mso-width-source: userset; mso-width-alt: 6570;">
<col width="91" style="width: 68pt; mso-width-source: userset; mso-width-alt: 3242;">
<col width="106" style="width: 79pt; mso-width-source: userset; mso-width-alt: 3754;">
<col width="94" style="width: 70pt; mso-width-source: userset; mso-width-alt: 3328;">
<col width="150" style="width: 113pt; mso-width-source: userset; mso-width-alt: 5347;">
<col width="195" style="width: 146pt; mso-width-source: userset; mso-width-alt: 6940;">
<col width="64" style="width: 48pt;" span="7">
</colgroup><tbody><tr height="21" style="height: 15.6pt;">
<td width="276" height="21" class="xl9825382" style="width: 207pt; height: 15.6pt;" colspan="2">Energy Information Administration</td>
<td width="106" class="xl9925382" style="width: 79pt;"></td>
<td width="94" class="xl9925382" style="width: 70pt;"></td>
<td width="150" class="xl6725382" style="width: 113pt;"></td>
<td width="195" class="xl6725382" style="width: 146pt;"></td>
<td width="64" class="xl1525382" style="width: 48pt;"></td>
<td width="64" class="xl1525382" style="width: 48pt;"></td>
<td width="64" class="xl1525382" style="width: 48pt;"></td>
<td width="64" class="xl1525382" style="width: 48pt;"></td>
<td width="64" class="xl1525382" style="width: 48pt;"></td>
<td width="64" class="xl1525382" style="width: 48pt;"></td>
<td width="64" class="xl1525382" style="width: 48pt;"></td>
Однако, когда я создаю из него объект soup
, затем печатаю его, символы возвращаются обратно к сущностям, и в первом случае это выглядит как HTML фрагмент: soup = BeautifulSoup(all_data_html, "html.parser")
Почему BeautifulSoup не распознает его как электронную почту? Это потому, что это переформатированная строка с невидимыми недостатками?