【发布时间】:2021-11-20 19:07:31
【问题描述】:
我每天都有通过 python 代码输入的数据:
id="ContentPlaceHolder1_cph_main_cph_main_SummaryGrid">\r\n\t\t<tr class="tr-header">\r\n\t\t\t<th scope="col"> </th><th class="right-align" scope="col">Share<br>Price</th><th class="right-align" scope="col">NAV</th><th class="right-align" scope="col">Premium/<br>Discount</th>\r\n\t\t</tr><tr>\r\n\t\t\t<td>Current</td><td class="right-align">$19.14</td><td class="right-align">$21.82</td><td class="right-align">-12.28%</td>\r\n\t\t</tr>
我需要提取 2 个价格和百分比值,在本例中为“$19.14”、“$21.82”和“-12.28%”,但我无法弄清楚如何解析和提取,有没有办法通过循环和搜索之前/之后的文本来做到这一点?
之前和之后的文本始终相同,但日期会发生变化。如果这种方法不可能,还有其他方法吗?非常感谢!
【问题讨论】:
-
可以使用
beautifulsoup等HTML解析器吗? -
“日期更改”是什么意思?根据识别的难易程度,您可以使用正则表达式或字符串方法。
-
我想我可以使用 beautifulsoup,但我仍然需要提取实际的信息,并且日期变化我的意思是日期每天都会变化
-
这能回答你的问题吗? Extracting data from HTML table
标签: python html web-scraping text-extraction information-extraction