简体   繁体   English

在 MySQL 5.7 中提取 HTML 标记内的数据

[英]Extract data inside HTML tags in MySQL 5.7

I am trying to extra data from inside html tags.我正在尝试从 html 标签中获取额外的数据。 I created a function to act as a split_string like in t-sql.我创建了一个函数来充当 t-sql 中的 split_string。 Although it doesnt work consistantly and was wondering what others have found.尽管它不能始终如一地工作,并且想知道其他人发现了什么。 I will try to include a example but it might not work since there is html tags all over it.我将尝试包含一个示例,但它可能无法正常工作,因为它上面到处都是 html 标签。

<div class="sub-sub-head"><b>Overview:</b></div>Establish and maintain an accurate, detailed, and up-to-date inventory of all enterprise assets with the potential to store or process data, to include: end-user devices (including portable and mobile), network devices, non-computing/IoT devices, and servers. Ensure the inventory records the network address (if static), hardware address, machine name, data asset owner, department for each asset, and whether the asset has been approved to connect to the network. For mobile end-user devices, MDM type tools can support this process, where appropriate. This inventory includes assets connected to the infrastructure physically, virtually, remotely, and those within cloud environments. Additionally, it includes assets that are regularly connected to the enterprise’s network infrastructure, even if they are not under control of the enterprise. Review and update the inventory of all enterprise assets bi-annually, or more frequently.<br/><br/>
 
 <div class="sub-sub-head"><b>Action Items:</b></div>1) Maintain a detailed Hardware Asset Inventory.<br/>
 
 <div class="sub-sub-head"><b>Additional Guidance:</b> </div>Asset Type: Devices <br> <br>
 Security Function: Identify

Use substring_index to split;使用 substring_index 进行拆分; for each field you call it twice, once to get the first N fields, and once to get the last field from that:对于每个字段,您调用它两次,一次获取前 N 个字段,一次获取最后一个字段:

select
    substring_index(substring_index(bar, '<div class="sub-sub-head">', 2), '<div class="sub-sub-head">', -1) overview,
    substring_index(substring_index(bar, '<div class="sub-sub-head">', 3), '<div class="sub-sub-head">', -1) action_items,
    substring_index(substring_index(bar, '<div class="sub-sub-head">', 4), '<div class="sub-sub-head">', -1) guidance
from foo;

fiddle 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM