html - 从标签外部提取 HTML我正在尝试提取位于<table>
标签上方和下方的 HTML 部分,例如从下面的示例 html 中:
sample_html = """
<html>
<title><b>Main Title</b></Title>
<b>more</b>
<b>stuff</b>
<
问题描述
我正在尝试提取位于<table>
标签上方和下方的 HTML 部分,例如从下面的示例 html 中:
sample_html = """
<html>
<title><b>Main Title</b></Title>
<b>more</b>
<b>stuff</b>
<b>in here!</b>
<table class="softwares" border="1" cellpadding="0" width="99%">
<thead style="background-color: #ededed">
<tr>
<td colspan="5"><b>Windows</b></td>
</tr>
</thead>
<tbody>
<tr>
<td><b>Type</b></td>
<td><b>Issue</b></td>
<td><b>Restart</b></td>
<td><b>Severity</b></td>
<td><b>Impact</b></td>
</tr>
<tr>
<td>some item</td>
<td><a href="some website">some website</a><br></td>
<td>Yes<br></td>
<td>Critical<br></td>
<td>stuff<br></td>
</tr>
<tr>
<td>some item</td>
<td><a href="some website">some website</a><br></td>
<td>Yes<br></td>
<td>Important<br></td>
<td>stuff<br></td>
</tr>
</tbody>
</table>
<b>AGAIN</b>
<b>more</b>
<b>stuff</b>
<b>down here!</b>
</html>
"""
我想获得类似的东西。
top_html = """
<html>
<title><b>Main Title</b></Title>
<b>more</b>
<b>stuff</b>
<b>in here!</b>
</html>
"""
bottom_html = """
<html>
<b>AGAIN</b>
<b>more</b>
<b>stuff</b>
<b>down here!</b>
</html>
"""
或者已经是文本格式,例如:
top_html = 'Main Title more stuff down here!'
bottom_html = 'AGAIN more stuff down here!'
所以我已经能够<table>
从整个 HTML 中提取部分并进行处理(我将行<tr>
和列分开,<td>
以便提取我需要的值),使用以下代码:
soup = BeautifulSoup(input_html, "html.parser")
table = soup.find('table')
如何以角度8循环iframe
iframe 一直在重新加载。有没有办法停止重新加载?
我的代码
<ng-container *ngFor="let element of elements">
<iframe
[src]="sanitizer.bypassSecurityTrustResourceUrl(element?.src)"
width="500"
height="500"
>
</iframe>
</ng-container>
解决方案
This solution doesn't extensively use BeautifulSoup but works.
Get index of opening and closing table tags, extract strings before and after.
soup = BeautifulSoup(sample_html, "html.parser")
def extract_top_and_bottom(soup):
index_of_opening_tag = soup.index("<table")
index_of_closing_tag = soup.index("</table>")
top_html = soup[:index_of_opening_tag]
bottom_html = soup[index_of_closing_tag::].replace("</table>", '')
print(top_html)
print(bottom_html)
extract_top_and_bottom(str(soup))
推荐阅读
- c# - 使用嵌套对象和中间步骤进行反序列化
- terraform - 在与 databricks 提供程序相同的配置中使用 databricks 工作区
- operating-system - 为进程安装信号处理程序?能不能说明下不能卸载?
- angular - RxJS 用另一个 Observable 中的值过滤一个 observable
- awk - 带有文本和多个分隔符的 sed
- pandas - 计算从 SAS INTCK 到 Python 的两个日期之间的月数
- amazon-web-services - Elastic Beanstalk 日志轮换到 S3
- informatica - Informatica - SQ 转换
- c# - 尝试建立安全消息传递时返回 6988 响应
- postgresql - 创建触发器的脚本,它将实现人工键的自动增量
我正在尝试提取位于<table>
标签上方和下方的 HTML 部分,例如从下面的示例 html 中:
sample_html = """
<html>
<title><b>Main Title</b></Title>
<b>more</b>
<b>stuff</b>
<
问题描述
我正在尝试提取位于<table>
标签上方和下方的 HTML 部分,例如从下面的示例 html 中:
sample_html = """
<html>
<title><b>Main Title</b></Title>
<b>more</b>
<b>stuff</b>
<b>in here!</b>
<table class="softwares" border="1" cellpadding="0" width="99%">
<thead style="background-color: #ededed">
<tr>
<td colspan="5"><b>Windows</b></td>
</tr>
</thead>
<tbody>
<tr>
<td><b>Type</b></td>
<td><b>Issue</b></td>
<td><b>Restart</b></td>
<td><b>Severity</b></td>
<td><b>Impact</b></td>
</tr>
<tr>
<td>some item</td>
<td><a href="some website">some website</a><br></td>
<td>Yes<br></td>
<td>Critical<br></td>
<td>stuff<br></td>
</tr>
<tr>
<td>some item</td>
<td><a href="some website">some website</a><br></td>
<td>Yes<br></td>
<td>Important<br></td>
<td>stuff<br></td>
</tr>
</tbody>
</table>
<b>AGAIN</b>
<b>more</b>
<b>stuff</b>
<b>down here!</b>
</html>
"""
我想获得类似的东西。
top_html = """
<html>
<title><b>Main Title</b></Title>
<b>more</b>
<b>stuff</b>
<b>in here!</b>
</html>
"""
bottom_html = """
<html>
<b>AGAIN</b>
<b>more</b>
<b>stuff</b>
<b>down here!</b>
</html>
"""
或者已经是文本格式,例如:
top_html = 'Main Title more stuff down here!'
bottom_html = 'AGAIN more stuff down here!'
所以我已经能够<table>
从整个 HTML 中提取部分并进行处理(我将行<tr>
和列分开,<td>
以便提取我需要的值),使用以下代码:
soup = BeautifulSoup(input_html, "html.parser")
table = soup.find('table')
iframe 一直在重新加载。有没有办法停止重新加载?
我的代码
<ng-container *ngFor="let element of elements">
<iframe
[src]="sanitizer.bypassSecurityTrustResourceUrl(element?.src)"
width="500"
height="500"
>
</iframe>
</ng-container>
This solution doesn't extensively use BeautifulSoup but works. Get index of opening and closing table tags, extract strings before and after.
soup = BeautifulSoup(sample_html, "html.parser")
def extract_top_and_bottom(soup):
index_of_opening_tag = soup.index("<table")
index_of_closing_tag = soup.index("</table>")
top_html = soup[:index_of_opening_tag]
bottom_html = soup[index_of_closing_tag::].replace("</table>", '')
print(top_html)
print(bottom_html)
extract_top_and_bottom(str(soup))