You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求:基于HTML表格生成PostgreSQL数据库建表脚本

需求说明

我需要从HTML表格创建PostgreSQL数据库表,目前仅能手动操作。手里有一份包含完整数据的HTML文档,但不清楚提取数据的最优方式。请根据提供的HTML内容生成PostgreSQL建表脚本,若字段类型含href链接,需关联对应目标表。


提供的HTML内容

<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ATOMS Definition for Type tom.service.soc.SocRecord</title>
<style type="text/css">
body
{
    line-height: 1.6em;
    font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
    font-size: 14px;
    margin: 45px;
}
#box-table-a
{
    font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
    font-size: 12px;
    margin: 5%;
    width: 90%;
    text-align: left;
    border-collapse: collapse;
}
#box-table-a th
{
    font-size: 13px;
    font-weight: normal;
    padding: 8px;
    background: #b9c9fe;
    border-top: 4px solid #aabcfe;
    border-bottom: 1px solid #fff;
    color: #039;
}
#box-table-a td
{
    padding: 8px;
    background: #e8edff;
    border-bottom: 1px solid #fff;
    color: #669;
    border-top: 1px solid transparent;
}
#box-table-a tr:hover td
{
    background: #d0dafd;
    color: #339;
}
</style>

</head>
<body>
<table id="box-table-a" summary="Definition for tom.service.soc.SocRecord">
    <thead>
        <tr><th colspan="2">tom.service.soc.SocRecord</th></tr>
    </thead>
    <tbody>
        <tr>
            <td>Version</td>
            <td>1</td>
        </tr>
        <tr>
            <td>Description</td>
            <td>[type is UNCLASSIFIED] Temporary dummy test object for SOC</td>
        </tr>
    </tbody>
</table>
<table id="box-table-a" summary="Fields Definition for Type tom.service.soc.SocRecord">
    <thead>
        <tr>
            <th scope="col">Index</th>
            <th scope="col">Name</th>
            <th scope="col">Type</th>
            <th scope="col">Range</th>
            <th scope="col">Default</th>
            <th scope="col" width="50%">Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>socID</td>
            <td>String</td>
            <td>           
-
            </td>
            <td>""</td>
            <td>
                [ ] The UUID of the tracked object -- String for transmission purposes  
            </td>
        </tr>
        <tr>
            <td>2</td>
            <td>satID</td>
            <td><a href="../../../../../tom/state/vcm/SatNumberType.html">SatNumberType</a></td>
            <td>
            </td>
            <td></td>
            <td>
                [ ] The ID of the tracked object -- copy of the satelliteId in the VCM  
            </td>
        </tr>
    </tbody>
</table>

</body></html>

参考建表示例

CREATE TABLE soc.SocRecord( 
    socId TEXT, --[ ] The UUID of the tracked object -- String for transmission purposes
    satId UUID, --[ ] The ID of the tracked object -- copy of the satId in the VCM
    commonName TEXT, --[ ] The name of the tracked object -- may be blank - 
                     --This field is optional in the current version of the message, check the set attribute before use.);

生成的PostgreSQL建表脚本

-- 创建必要的Schema(若不存在)
CREATE SCHEMA IF NOT EXISTS soc;
CREATE SCHEMA IF NOT EXISTS tom_state_vcm;

-- 先创建关联的SatNumberType表(字段类型可根据SatNumberType的实际定义调整)
CREATE TABLE IF NOT EXISTS tom_state_vcm.SatNumberType (
    id INT PRIMARY KEY,
    description TEXT -- 可根据实际需求补充其他字段
);

-- 创建SocRecord主表
CREATE TABLE soc.SocRecord( 
    soc_id TEXT DEFAULT '' PRIMARY KEY, -- [ ] 被跟踪对象的UUID -- 用于传输的字符串类型
    sat_id INT REFERENCES tom_state_vcm.SatNumberType(id) -- [ ] 被跟踪对象的ID -- 复制自VCM中的satelliteId
);

数据提取优化建议

  • 手动操作时,可通过浏览器开发者工具(F12)定位到目标表格,右键选择「复制」→「复制为表格」,粘贴到Excel/Google Sheets中整理后,导出为CSV格式批量导入数据库
  • 若后续有大量类似需求,可使用Python的BeautifulSoup库编写脚本,自动解析HTML表格字段信息并生成建表语句,减少重复手动工作

内容的提问来源于stack exchange,提问作者e417927

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 12:07:03