当前位置:首页 > 文章列表 > 文章 > python教程 > Python解析XML:ElementTree使用指南

Python解析XML:ElementTree使用指南

2025-07-08 16:05:38 0浏览 收藏

Python处理XML数据,ElementTree是标准库中的首选,它以其直观高效的方式,简化了XML文档的解析、操作与生成。无需额外安装,ElementTree即可轻松应对日常XML处理任务。本文将深入探讨ElementTree的核心步骤,包括XML解析、元素查找、数据访问、结构修改以及写回文件。针对大型XML文件,推荐使用iterparse()实现流式解析,有效避免内存问题。同时,本文还将介绍处理XML命名空间的方法,以及lxml、minidom和sax等其他Python XML处理库的特点,助你根据实际需求选择最合适的工具,提升XML数据处理效率。

Python处理XML数据首选ElementTree,其核心步骤为:1.解析XML;2.查找元素;3.访问数据;4.修改结构;5.写回文件。ElementTree无需额外安装,功能强大且直观高效,支持从字符串或文件解析,通过find()、findall()等方法查找元素,并能创建、修改和删除节点。处理大型XML时推荐使用iterparse()实现流式解析,避免内存问题。对于命名空间,需手动拼接QName或通过字典辅助构造完整标签名。此外,Python还有lxml(性能强、支持XPath/XSLT)、minidom(标准DOM风格)和sax(事件驱动)等库应对不同需求。

怎样用Python处理XML数据?ElementTree解析方法

Python处理XML数据,ElementTree无疑是标准库中的首选,它提供了一种直观且高效的方式来解析、操作和生成XML文档。在我看来,它最大的优点在于“开箱即用”,不需要额外安装任何库,对于大多数日常的XML处理任务来说,它的功能已经足够强大了。

怎样用Python处理XML数据?ElementTree解析方法

解决方案

使用ElementTree处理XML数据,通常会经历几个核心步骤:解析XML、查找元素、访问数据、修改结构,以及最后将修改写回文件。整个过程,说实话,挺符合我们对树形数据结构操作的直觉。

怎样用Python处理XML数据?ElementTree解析方法

首先,你需要导入xml.etree.ElementTree模块,通常我们会把它简写成ET,这样代码看起来更简洁。

import xml.etree.ElementTree as ET

# 假设我们有一个XML字符串或者一个XML文件
xml_string = """
<catalog>
    <book id="bk101">
        <author>Gambardella, Matthew</author>
        <title>XML Developer's Guide</title>
        <genre>Computer</genre>
        <price>44.95</price>
        <publish_date>2000-10-01</publish_date>
        <description>An in-depth look at creating applications with XML.</description>
    </book>
    <book id="bk102">
        <author>Ralls, Kim</author>
        <title>Midnight Rain</title>
        <genre>Fantasy</genre>
        <price>5.95</price>
        <publish_date>2000-12-16</publish_date>
        <description>A young man's struggle to come to grips with his tumultuous past.</description>
    </book>
</catalog>
"""

# 1. 解析XML数据
# 如果是字符串,用fromstring()
root = ET.fromstring(xml_string)

# 如果是文件,用parse()
# tree = ET.parse('your_file.xml')
# root = tree.getroot() # 获取根元素

解析完成后,我们就得到了一个Element对象,它代表了XML的根元素。接下来就是如何在这个树里“寻宝”了。

怎样用Python处理XML数据?ElementTree解析方法
# 2. 查找元素和访问数据
# 获取根元素的标签名
print(f"根元素: {root.tag}") # 输出: 根元素: catalog

# 遍历所有直接子元素
print("\n所有书籍信息:")
for book in root:
    print(f"  书本ID: {book.get('id')}") # 获取元素的属性值,用.get()方法
    print(f"  作者: {book.find('author').text}") # 查找子元素,并获取其文本内容,用.text属性
    print(f"  标题: {book.find('title').text}")
    print("-" * 20)

# 查找特定元素:比如找到所有价格大于10的书
print("\n价格大于10的书:")
for book in root.findall('book'): # findall() 返回所有匹配的子元素列表
    price_elem = book.find('price')
    if price_elem is not None and float(price_elem.text) > 10:
        print(f"  标题: {book.find('title').text}, 价格: {price_elem.text}")

ElementTree的find()方法只返回第一个匹配的子元素,而findall()则返回所有匹配的子元素列表。对于更复杂的查找,比如基于属性值,你可能需要结合循环和条件判断,或者稍微变通一下。

# 3. 修改XML结构
# 比如,给第一本书添加一个“库存”信息
first_book = root.find('book') # 获取第一本书
if first_book is not None:
    # 创建新元素并添加到first_book下
    stock_elem = ET.SubElement(first_book, 'stock')
    stock_elem.text = '100'
    print("\n添加库存信息后的第一本书结构:")
    ET.dump(first_book) # 临时打印Element内容,方便调试

# 修改一个现有元素的值
# 比如,把第二本书的价格改为6.95
second_book = root.findall('book')[1] # 获取第二本书
if second_book is not None:
    price_elem = second_book.find('price')
    if price_elem is not None:
        price_elem.text = '6.95'
        print(f"\n第二本书的新价格: {price_elem.text}")

# 删除一个元素
# 比如,删除第一本书的描述信息
desc_elem = first_book.find('description')
if desc_elem is not None:
    first_book.remove(desc_elem)
    print("\n删除描述信息后的第一本书结构:")
    ET.dump(first_book)

操作完成后,通常需要将修改后的XML写回到文件。

# 4. 将修改写回XML文件
# tree = ET.ElementTree(root) # 如果一开始是用parse()创建的tree对象,直接用它
# 如果是从字符串fromstring()创建的,需要重新创建一个ElementTree对象
modified_tree = ET.ElementTree(root)

# write()方法可以指定输出文件、编码和是否包含XML声明
# modified_tree.write('modified_catalog.xml', encoding='utf-8', xml_declaration=True)

# 也可以直接打印到控制台,便于查看完整结构
print("\n最终修改后的XML内容:")
ET.dump(root)

ElementTree的API设计得非常简洁,这让它在处理大多数XML任务时显得游刃有余。当然,它也有自己的特点,比如对XPath支持的有限性,有时候会让我觉得需要多写几行代码来达到目的,但总体而言,它是一个非常可靠的工具。

处理XML命名空间时ElementTree有哪些注意事项?

命名空间(Namespace)在XML中是一个挺常见的概念,它主要是为了避免元素或属性名称冲突。比如,两个不同的XML方言可能都有一个</code>元素,但它们代表的含义完全不同。命名空间就是用来区分这些的。我个人觉得,处理命名空间是ElementTree新手最容易“踩坑”的地方。</p><p>ElementTree在解析带有命名空间的XML时,会将命名空间URI和本地名称组合起来,形成一个“QName”格式的标签,比如<code>{http://www.example.com/ns}element_name</code>。这意味着,如果你直接用<code>find('element_name')</code>去查找,很可能什么都找不到,因为你没有提供完整的QName。</p><p>我的经验是,通常有两种处理方式:</p><ol><li><p><strong>使用完整的QName字符串</strong>:这是最直接的方式,但缺点是如果命名空间URI很长,代码会显得比较冗长,可读性会差一些。</p><pre>ns_xml = """ <data xmlns="http://www.example.com/ns" xmlns:prod="http://www.example.com/products"> <item> <prod:name>Laptop</prod:name> <prod:price>1200</prod:price> </item> </data> """ root_ns = ET.fromstring(ns_xml) # 查找默认命名空间下的item item = root_ns.find('{http://www.example.com/ns}item') if item is not None: print(f"\n找到的item标签: {item.tag}") # 查找带有前缀的命名空间下的name prod_name = item.find('{http://www.example.com/products}name') if prod_name is not None: print(f" 产品名称: {prod_name.text}")</pre></li><li><p><strong>通过<code>namespaces</code>参数传递命名空间字典</strong>:这是我更推荐的方式,尤其是当XML文档中包含多个命名空间,或者你希望代码更清晰时。你可以定义一个字典,将命名空间前缀映射到它们的URI。这样,在<code>find()</code>或<code>findall()</code>时,你就可以使用更简洁的“前缀:标签名”格式,并把这个字典传给<code>namespaces</code>参数。</p><pre>namespaces = { 'default': 'http://www.example.com/ns', 'prod': 'http://www.example.com/products' } # 注意:这里find/findall的第一个参数依然是完整的QName,但ElementTree的某些版本或lxml库支持直接使用前缀。 # 对于标准库ElementTree,你仍然需要拼接完整的QName或者在find/findall方法中传入namespaces参数(如果方法支持)。 # 实际上,ElementTree的find/findall方法本身不直接接受namespaces参数来解析前缀。 # 你依然需要手动构造QName,或者通过迭代来处理。 # 比如: item_by_ns = root_ns.find(f"{{{namespaces['default']}}}item") if item_by_ns: print(f"\n通过字典和拼接找到的item标签: {item_by_ns.tag}") prod_name_by_ns = item_by_ns.find(f"{{{namespaces['prod']}}}name") if prod_name_by_ns: print(f" 通过字典和拼接找到的产品名称: {prod_name_by_ns.text}") # 另一种更通用的做法是,直接处理根元素的命名空间,然后查找。 # ElementTree.QName 可以帮助构造完整的QName # from xml.etree.ElementTree import QName # qname_item = QName(namespaces['default'], 'item') # item_qname = root_ns.find(qname_item.text) # if item_qname: # print(f"通过QName对象找到的item标签: {item_qname.tag}")</pre><p>这里需要澄清一下,标准库的<code>ElementTree.find()</code>和<code>findall()</code>方法本身并没有直接的<code>namespaces</code>参数让你传入字典来解析<code>'prod:name'</code>这种形式。你仍然需要手动构造完整的QName字符串,或者在遍历时做处理。<code>lxml</code>库在这方面提供了更方便的XPath支持,可以直接使用前缀。这可能是我之前使用<code>lxml</code>比较多,思维有点跳跃了。对于纯粹的ElementTree,记住要用完整的URI来查找,或者自己写个小函数来辅助构造QName。</p></li></ol><h3>如何高效处理大型XML文件,避免内存问题?</h3><p>处理大型XML文件确实是个挑战,尤其是当文件大到无法一次性加载到内存中时。如果直接使用<code>ET.parse()</code>,它会把整个XML文件解析成一个完整的ElementTree对象,这对于几个GB大小的文件来说,内存占用会非常恐怖,甚至直接导致程序崩溃。</p><p>这时候,我通常会转向<code>ET.iterparse()</code>。它提供了一种事件驱动的解析方式,不会一次性加载整个文档。它会逐个元素地解析,并在遇到开始标签、结束标签或文本内容时触发事件。这就像是“流式”处理,你只需要处理当前事件对应的元素,处理完就可以释放它的内存,而不是把所有东西都留在内存里。</p><pre># 假设有一个非常大的XML文件 'large_data.xml' # 为了演示,我们先模拟一个大文件内容 import io large_xml_content = """<root>""" for i in range(10000): # 模拟10000个item large_xml_content += f"<item id='{i}'><name>Item {i}</name><value>{i*10}</value></item>" large_xml_content += "</root>" # 使用io.StringIO来模拟文件对象 xml_file_like_object = io.StringIO(large_xml_content) # 使用iterparse进行事件驱动解析 # iterparse() 返回一个迭代器,每次迭代产生 (event, element) 对 # event 可以是 'start', 'end', 'start-ns', 'end-ns' # element 是当前事件对应的Element对象 print("\n使用iterparse处理大型XML文件:") total_value = 0 # 指定events=['end'],只在遇到元素的结束标签时处理,这样可以确保元素的所有子内容都已解析 for event, elem in ET.iterparse(xml_file_like_object, events=['end']): if elem.tag == 'item': # 找到item元素,处理其子元素 value_elem = elem.find('value') if value_elem is not None: try: total_value += int(value_elem.text) except (ValueError, TypeError): print(f"警告: 无法解析item {elem.get('id')} 的值.") # 重点:处理完当前元素后,清除它及其子元素的引用 # 这样ElementTree就可以释放这些元素占用的内存 elem.clear() # 清除当前元素的子元素和属性 print(f"所有item的总值: {total_value}") # 重新定位到文件开头,以便再次解析(如果需要) xml_file_like_object.seek(0) # 如果你只需要某个特定标签的元素,可以在iterparse时指定tag参数 # 比如只处理<item>标签的结束事件 print("\n使用iterparse指定标签处理:") item_count = 0 for event, elem in ET.iterparse(xml_file_like_object, events=['end'], tag='item'): item_count += 1 # 这里也可以对elem进行处理 elem.clear() # 同样,处理完就清除 print(f"总共有 {item_count} 个item元素。")</pre><p><code>iterparse</code>的关键在于<code>elem.clear()</code>这一步。如果没有它,ElementTree仍然会把所有解析过的元素保留在内存中,导致内存泄漏。<code>clear()</code>方法会移除元素的子元素和属性,从而让Python的垃圾回收机制能够回收这些不再需要的对象。这就像是你在处理完一页文件后,立刻把它撕掉扔进碎纸机,而不是堆在桌上直到整个房间都满了。</p><h3>除了ElementTree,Python还有哪些处理XML的库,它们各有什么特点?</h3><p>ElementTree作为标准库的一部分,确实很方便。但如果你的需求更复杂,或者对性能有极高的要求,Python生态系统里还有其他一些非常出色的XML处理库,它们各有侧重。</p><ol><li><p><strong>lxml</strong>:</p><ul><li><strong>特点</strong>:这是我个人在ElementTree无法满足需求时,最常转向的库。<code>lxml</code>是Python绑定了C语言库<code>libxml2</code>和<code>libxslt</code>的结果,所以它的<strong>性能非常卓越</strong>,通常比ElementTree快很多倍,尤其是在处理大型文件时。</li><li><strong>功能</strong>:它不仅提供了与ElementTree兼容的API(意味着你可以很平滑地从ElementTree迁移),还<strong>完整支持XPath和XSLT</strong>。这意味着你可以用非常简洁强大的XPath表达式来查找元素,这在处理复杂XML结构时简直是神器。它也支持SAX和DOM解析方式。</li><li><strong>适用场景</strong>:对性能有严格要求、需要复杂XPath查询、或者需要进行XSLT转换的场景。不过,它不是标准库,需要额外安装。</li></ul></li><li><p><strong>xml.dom.minidom</strong>:</p><ul><li><strong>特点</strong>:这也是Python标准库的一部分,提供了一个轻量级的DOM(Document Object Model)实现。DOM解析器会将整个XML文档加载到内存中,并构建一个完整的树形结构,然后你可以通过这个树来导航和操作。</li><li><strong>功能</strong>:它提供了符合W3C DOM标准的API,这使得它在某些方面比ElementTree更“规范”,比如它区分元素节点、文本节点、属性节点等。它的API通常比较冗长,需要更多的代码来完成相同的任务。</li><li><strong>适用场景</strong>:如果你需要严格遵循DOM模型,或者XML文档不是特别大,并且你习惯于DOM风格的API。不过,在大多数情况下,ElementTree的简洁性往往更受欢迎。</li></ul></li><li><p><strong>xml.sax</strong>:</p><ul><li><strong>特点</strong>:SAX(Simple API for XML)是一个事件驱动的解析器。与DOM和ElementTree不同,SAX不会构建整个XML文档的内存表示。它在解析过程中,当遇到XML文档中的特定事件(如开始标签、结束标签、文本内容)时,会调用你提供的回调函数。</li><li>**</li></ul></li></ol><p>以上就是本文的全部内容了,是否有顺利帮助你解决问题?若是能给你带来学习上的帮助,请大家多多支持golang学习网!更多关于文章的相关知识,也可关注golang学习网公众号。</p> </div> <div class="labsList"> </div> <div class="cateBox"> <div class="cateItem"> <a href="/article/254604.html" title="用Golang开发命令行工具全攻略" class="img_box"> <img src="/uploads/20250708/1751961864686cd108ee42f.jpg" onerror="this.onerror='',this.src='/assets/images/moren/morentu.png'" alt="用Golang开发命令行工具全攻略">用Golang开发命令行工具全攻略 </a> <dl> <dt class="lineOverflow"><a href="/article/254604.html" title="用Golang开发命令行工具全攻略" class="aBlack">上一篇<i></i></a></dt> <dd class="lineTwoOverflow">用Golang开发命令行工具全攻略</dd> </dl> </div> <div class="cateItem"> <a href="/article/254606.html" title="Java读写CSV文件全攻略" class="img_box"> <img src="/uploads/20250708/1751961988686cd184dfce4.jpg" onerror="this.onerror='',this.src='/assets/images/moren/morentu.png'" alt="Java读写CSV文件全攻略"> </a> <dl> <dt class="lineOverflow"><a href="/article/254606.html" class="aBlack" title="Java读写CSV文件全攻略">下一篇<i></i></a></dt> <dd class="lineTwoOverflow">Java读写CSV文件全攻略</dd> </dl> </div> </div> </div> </div> <div class="leftContBox pt0"> <div class="pdl20"> <div class="contTit"> <a href="/articlelist.html" class="more" title="查看更多">查看更多<i class="iconfont"></i></a> <div class="tit">最新文章</div> </div> </div> <ul class="newArticleList"> <li> <div class="contBox"> <a href="/article/255193.html" class="img_box" title="Python中abs的作用及使用方法"> <img src="/uploads/20250708/1751990248686d3fe862bcf.jpg" onerror="this.src='/assets/images/moren/morentu.png'" alt="Python中abs的作用及使用方法"> </a> <dl> <dd class="cont1"> <span> <a href="/articlelist/19_new_0_1.html" class="aLightGray" title="文章">文章</a> · <a href="/articlelist/86_new_0_1.html" class="aLightGray" title="python教程">python教程</a>   |  7分钟前  |   </span> </dd> <dt class="lineOverflow"> <a href="/article/255193.html" class="aBlack" target="_blank" title="Python中abs的作用及使用方法">Python中abs的作用及使用方法</a> </dt> <dd class="cont2"> <span><i class="view"></i>284浏览</span> <span class="collectBtn user_collection" data-id="255193" data-type="article" title="收藏"><i class="collect"></i>收藏</span> </dd> </dl> </div> </li> <li> <div class="contBox"> <a href="/article/255190.html" class="img_box" title="Python反爬技巧与爬虫伪装指南"> <img src="/uploads/20250708/1751990131686d3f73e24d1.jpg" onerror="this.src='/assets/images/moren/morentu.png'" alt="Python反爬技巧与爬虫伪装指南"> </a> <dl> <dd class="cont1"> <span> <a href="/articlelist/19_new_0_1.html" class="aLightGray" title="文章">文章</a> · <a href="/articlelist/86_new_0_1.html" class="aLightGray" title="python教程">python教程</a>   |  9分钟前  |   </span> </dd> <dt class="lineOverflow"> <a href="/article/255190.html" class="aBlack" target="_blank" title="Python反爬技巧与爬虫伪装指南">Python反爬技巧与爬虫伪装指南</a> </dt> <dd class="cont2"> <span><i class="view"></i>469浏览</span> <span class="collectBtn user_collection" data-id="255190" data-type="article" title="收藏"><i class="collect"></i>收藏</span> </dd> </dl> </div> </li> <li> <div class="contBox"> <a href="/article/255189.html" class="img_box" title="Python科学计算入门:Numpy快速上手指南"> <img src="/uploads/20250708/1751990069686d3f3595f32.png" onerror="this.src='/assets/images/moren/morentu.png'" alt="Python科学计算入门:Numpy快速上手指南"> </a> <dl> <dd class="cont1"> <span> <a href="/articlelist/19_new_0_1.html" class="aLightGray" title="文章">文章</a> · <a href="/articlelist/86_new_0_1.html" class="aLightGray" title="python教程">python教程</a>   |  10分钟前  |   </span> </dd> <dt class="lineOverflow"> <a href="/article/255189.html" class="aBlack" target="_blank" title="Python科学计算入门:Numpy快速上手指南">Python科学计算入门:Numpy快速上手指南</a> </dt> <dd class="cont2"> <span><i class="view"></i>249浏览</span> <span class="collectBtn user_collection" data-id="255189" data-type="article" title="收藏"><i class="collect"></i>收藏</span> </dd> </dl> </div> </li> <li> <div class="contBox"> <a href="/article/255182.html" class="img_box" title="Python图片处理教程:Pillow库使用技巧"> <img src="/uploads/20250708/1751989761686d3e019573a.png" onerror="this.src='/assets/images/moren/morentu.png'" alt="Python图片处理教程:Pillow库使用技巧"> </a> <dl> <dd class="cont1"> <span> <a href="/articlelist/19_new_0_1.html" class="aLightGray" title="文章">文章</a> · <a href="/articlelist/86_new_0_1.html" class="aLightGray" title="python教程">python教程</a>   |  15分钟前  |   </span> </dd> <dt class="lineOverflow"> <a href="/article/255182.html" class="aBlack" target="_blank" title="Python图片处理教程:Pillow库使用技巧">Python图片处理教程:Pillow库使用技巧</a> </dt> <dd class="cont2"> <span><i class="view"></i>256浏览</span> <span class="collectBtn user_collection" data-id="255182" data-type="article" title="收藏"><i class="collect"></i>收藏</span> </dd> </dl> </div> </li> <li> <div class="contBox"> <a href="/article/255175.html" class="img_box" title="Python操作Excel的实用技巧汇总"> <img src="/uploads/20250708/1751989526686d3d16cea57.png" onerror="this.src='/assets/images/moren/morentu.png'" alt="Python操作Excel的实用技巧汇总"> </a> <dl> <dd class="cont1"> <span> <a href="/articlelist/19_new_0_1.html" class="aLightGray" title="文章">文章</a> · <a href="/articlelist/86_new_0_1.html" class="aLightGray" title="python教程">python教程</a>   |  19分钟前  |   </span> </dd> <dt class="lineOverflow"> <a href="/article/255175.html" class="aBlack" target="_blank" title="Python操作Excel的实用技巧汇总">Python操作Excel的实用技巧汇总</a> </dt> <dd class="cont2"> <span><i class="view"></i>149浏览</span> <span class="collectBtn user_collection" data-id="255175" data-type="article" title="收藏"><i class="collect"></i>收藏</span> </dd> </dl> </div> </li> <li> <div class="contBox"> <a href="/article/255170.html" class="img_box" title="Python文件监控教程:watchdog库使用指南"> <img src="/uploads/20250708/1751989168686d3bb0e5a5d.png" onerror="this.src='/assets/images/moren/morentu.png'" alt="Python文件监控教程:watchdog库使用指南"> </a> <dl> <dd class="cont1"> <span> <a href="/articlelist/19_new_0_1.html" class="aLightGray" title="文章">文章</a> · <a href="/articlelist/86_new_0_1.html" class="aLightGray" title="python教程">python教程</a>   |  25分钟前  |   </span> </dd> <dt class="lineOverflow"> <a href="/article/255170.html" class="aBlack" target="_blank" title="Python文件监控教程:watchdog库使用指南">Python文件监控教程:watchdog库使用指南</a> </dt> <dd class="cont2"> <span><i class="view"></i>145浏览</span> <span class="collectBtn user_collection" data-id="255170" data-type="article" title="收藏"><i class="collect"></i>收藏</span> </dd> </dl> </div> </li> <li> <div class="contBox"> <a href="/article/255162.html" class="img_box" title="Python面试题高频解析大全"> <img src="/uploads/20250708/1751988805686d3a456c0d0.png" onerror="this.src='/assets/images/moren/morentu.png'" alt="Python面试题高频解析大全"> </a> <dl> <dd class="cont1"> <span> <a href="/articlelist/19_new_0_1.html" class="aLightGray" title="文章">文章</a> · <a href="/articlelist/86_new_0_1.html" class="aLightGray" title="python教程">python教程</a>   |  31分钟前  |   </span> </dd> <dt class="lineOverflow"> <a href="/article/255162.html" class="aBlack" target="_blank" title="Python面试题高频解析大全">Python面试题高频解析大全</a> </dt> <dd class="cont2"> <span><i class="view"></i>251浏览</span> <span class="collectBtn user_collection" data-id="255162" data-type="article" title="收藏"><i class="collect"></i>收藏</span> </dd> </dl> </div> </li> <li> <div class="contBox"> <a href="/article/255154.html" class="img_box" title="Python中abs函数的作用与用法详解"> <img src="/uploads/20250708/1751988447686d38df6869b.jpg" onerror="this.src='/assets/images/moren/morentu.png'" alt="Python中abs函数的作用与用法详解"> </a> <dl> <dd class="cont1"> <span> <a href="/articlelist/19_new_0_1.html" class="aLightGray" title="文章">文章</a> · <a href="/articlelist/86_new_0_1.html" class="aLightGray" title="python教程">python教程</a>   |  37分钟前  |   </span> </dd> <dt class="lineOverflow"> <a href="/article/255154.html" class="aBlack" target="_blank" title="Python中abs函数的作用与用法详解">Python中abs函数的作用与用法详解</a> </dt> <dd class="cont2"> <span><i class="view"></i>159浏览</span> <span class="collectBtn user_collection" data-id="255154" data-type="article" title="收藏"><i class="collect"></i>收藏</span> </dd> </dl> </div> </li> <li> <div class="contBox"> <a href="/article/255150.html" class="img_box" title="Python构建知识图谱,Neo4j实战教程"> <img src="/uploads/20250708/1751988211686d37f3176d8.png" onerror="this.src='/assets/images/moren/morentu.png'" alt="Python构建知识图谱,Neo4j实战教程"> </a> <dl> <dd class="cont1"> <span> <a href="/articlelist/19_new_0_1.html" class="aLightGray" title="文章">文章</a> · <a href="/articlelist/86_new_0_1.html" class="aLightGray" title="python教程">python教程</a>   |  41分钟前  |   </span> </dd> <dt class="lineOverflow"> <a href="/article/255150.html" class="aBlack" target="_blank" title="Python构建知识图谱,Neo4j实战教程">Python构建知识图谱,Neo4j实战教程</a> </dt> <dd class="cont2"> <span><i class="view"></i>103浏览</span> <span class="collectBtn user_collection" data-id="255150" data-type="article" title="收藏"><i class="collect"></i>收藏</span> </dd> </dl> </div> </li> <li> <div class="contBox"> <a href="/article/255147.html" class="img_box" title="元类创建的类是“类型对象”或“类类型”。"> <img src="/uploads/20250708/1751988084686d3774a2dc0.jpg" onerror="this.src='/assets/images/moren/morentu.png'" alt="元类创建的类是“类型对象”或“类类型”。"> </a> <dl> <dd class="cont1"> <span> <a href="/articlelist/19_new_0_1.html" class="aLightGray" title="文章">文章</a> · <a href="/articlelist/86_new_0_1.html" class="aLightGray" title="python教程">python教程</a>   |  43分钟前  |   </span> </dd> <dt class="lineOverflow"> <a href="/article/255147.html" class="aBlack" target="_blank" title="元类创建的类是“类型对象”或“类类型”。">元类创建的类是“类型对象”或“类类型”。</a> </dt> <dd class="cont2"> <span><i class="view"></i>368浏览</span> <span class="collectBtn user_collection" data-id="255147" data-type="article" title="收藏"><i class="collect"></i>收藏</span> </dd> </dl> </div> </li> <li> <div class="contBox"> <a href="/article/255133.html" class="img_box" title="Python办公自动化:Excel与Word实用技巧"> <img src="/uploads/20250708/1751987422686d34de73787.jpg" onerror="this.src='/assets/images/moren/morentu.png'" alt="Python办公自动化:Excel与Word实用技巧"> </a> <dl> <dd class="cont1"> <span> <a href="/articlelist/19_new_0_1.html" class="aLightGray" title="文章">文章</a> · <a href="/articlelist/86_new_0_1.html" class="aLightGray" title="python教程">python教程</a>   |  54分钟前  |   </span> </dd> <dt class="lineOverflow"> <a href="/article/255133.html" class="aBlack" target="_blank" title="Python办公自动化:Excel与Word实用技巧">Python办公自动化:Excel与Word实用技巧</a> </dt> <dd class="cont2"> <span><i class="view"></i>264浏览</span> <span class="collectBtn user_collection" data-id="255133" data-type="article" title="收藏"><i class="collect"></i>收藏</span> </dd> </dl> </div> </li> <li> <div class="contBox"> <a href="/article/255129.html" class="img_box" title="Python图像识别教程:OpenCV深度学习实战"> <img src="/uploads/20250708/1751987310686d346e6f64c.png" onerror="this.src='/assets/images/moren/morentu.png'" alt="Python图像识别教程:OpenCV深度学习实战"> </a> <dl> <dd class="cont1"> <span> <a href="/articlelist/19_new_0_1.html" class="aLightGray" title="文章">文章</a> · <a href="/articlelist/86_new_0_1.html" class="aLightGray" title="python教程">python教程</a>   |  56分钟前  |   </span> </dd> <dt class="lineOverflow"> <a href="/article/255129.html" class="aBlack" target="_blank" title="Python图像识别教程:OpenCV深度学习实战">Python图像识别教程:OpenCV深度学习实战</a> </dt> <dd class="cont2"> <span><i class="view"></i>321浏览</span> <span class="collectBtn user_collection" data-id="255129" data-type="article" title="收藏"><i class="collect"></i>收藏</span> </dd> </dl> </div> </li> </ul> </div> </div> <div class="mainRight"> <!-- 右侧广告位banner --> <div class="rightContBox" style="margin-top: 0px;"> <div class="rightTit"> <a href="/courselist.html" class="more" title="查看更多">查看更多<i class="iconfont"></i></a> <div class="tit lineOverflow">课程推荐</div> </div> <ul class="lessonRecomRList"> <li> <a href="/course/9.html" class="img_box" target="_blank" title="前端进阶之JavaScript设计模式"> <img src="/uploads/20221222/52fd0f23a454c71029c2c72d206ed815.jpg" onerror="this.onerror='',this.src='/assets/images/moren/morentu.png'" alt="前端进阶之JavaScript设计模式"> </a> <dl> <dt class="lineTwoOverflow"><a href="/course/9.html" target="_blank" class="aBlack" title="前端进阶之JavaScript设计模式">前端进阶之JavaScript设计模式</a></dt> <dd class="cont1 lineTwoOverflow"> 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。 </dd> <dd class="cont2">542次学习</dd> </dl> </li> <li> <a href="/course/2.html" class="img_box" target="_blank" title="GO语言核心编程课程"> <img src="/uploads/20221221/634ad7404159bfefc6a54a564d437b5f.png" onerror="this.onerror='',this.src='/assets/images/moren/morentu.png'" alt="GO语言核心编程课程"> </a> <dl> <dt class="lineTwoOverflow"><a href="/course/2.html" target="_blank" class="aBlack" title="GO语言核心编程课程">GO语言核心编程课程</a></dt> <dd class="cont1 lineTwoOverflow"> 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。 </dd> <dd class="cont2">509次学习</dd> </dl> </li> <li> <a href="/course/74.html" class="img_box" target="_blank" title="简单聊聊mysql8与网络通信"> <img src="/uploads/20240103/bad35fe14edbd214bee16f88343ac57c.png" onerror="this.onerror='',this.src='/assets/images/moren/morentu.png'" alt="简单聊聊mysql8与网络通信"> </a> <dl> <dt class="lineTwoOverflow"><a href="/course/74.html" target="_blank" class="aBlack" title="简单聊聊mysql8与网络通信">简单聊聊mysql8与网络通信</a></dt> <dd class="cont1 lineTwoOverflow"> 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让 </dd> <dd class="cont2">497次学习</dd> </dl> </li> <li> <a href="/course/57.html" class="img_box" target="_blank" title="JavaScript正则表达式基础与实战"> <img src="/uploads/20221226/bbe4083bb3cb0dd135fb02c31c3785fb.jpg" onerror="this.onerror='',this.src='/assets/images/moren/morentu.png'" alt="JavaScript正则表达式基础与实战"> </a> <dl> <dt class="lineTwoOverflow"><a href="/course/57.html" target="_blank" class="aBlack" title="JavaScript正则表达式基础与实战">JavaScript正则表达式基础与实战</a></dt> <dd class="cont1 lineTwoOverflow"> 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。 </dd> <dd class="cont2">487次学习</dd> </dl> </li> <li> <a href="/course/28.html" class="img_box" target="_blank" title="从零制作响应式网站—Grid布局"> <img src="/uploads/20221223/ac110f88206daeab6c0cf38ebf5fe9ed.jpg" onerror="this.onerror='',this.src='/assets/images/moren/morentu.png'" alt="从零制作响应式网站—Grid布局"> </a> <dl> <dt class="lineTwoOverflow"><a href="/course/28.html" target="_blank" class="aBlack" title="从零制作响应式网站—Grid布局">从零制作响应式网站—Grid布局</a></dt> <dd class="cont1 lineTwoOverflow"> 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。 </dd> <dd class="cont2">484次学习</dd> </dl> </li> </ul> </div> <div class="rightContBox"> <div class="rightTit"> <a href="/ai.html" class="more" title="查看更多">查看更多<i class="iconfont"></i></a> <div class="tit lineOverflow">AI推荐</div> </div> <ul class="lessonRecomRList"> <li> <a href="/ai/13015.html" target="_blank" title="AI边界平台:智能对话、写作、画图,一站式解决方案" class="img_box"> <img src="/uploads/20250704/175161663468678c7a366f5.jpg" onerror="this.onerror='',this.src='/assets/images/moren/morentu.png'" alt="AI边界平台:智能对话、写作、画图,一站式解决方案" style="object-fit:cover;width:100%;height:100%;"> </a> <dl> <dt class="lineTwoOverflow"><a href="/ai/13015.html" class="aBlack" target="_blank" title="边界AI平台">边界AI平台</a></dt> <dd class="cont1 lineTwoOverflow"> 探索AI边界平台,领先的智能AI对话、写作与画图生成工具。高效便捷,满足多样化需求。立即体验! </dd> <dd class="cont2">319次使用</dd> </dl> </li> <li> <a href="/ai/13014.html" target="_blank" title="讯飞AI大学堂免费AI认证证书:大模型工程师认证,提升您的职场竞争力" class="img_box"> <img src="/uploads/20250630/17512710036862465b845ee.jpg" onerror="this.onerror='',this.src='/assets/images/moren/morentu.png'" alt="讯飞AI大学堂免费AI认证证书:大模型工程师认证,提升您的职场竞争力" style="object-fit:cover;width:100%;height:100%;"> </a> <dl> <dt class="lineTwoOverflow"><a href="/ai/13014.html" class="aBlack" target="_blank" title="免费AI认证证书">免费AI认证证书</a></dt> <dd class="cont1 lineTwoOverflow"> 科大讯飞AI大学堂推出免费大模型工程师认证,助力您掌握AI技能,提升职场竞争力。体系化学习,实战项目,权威认证,助您成为企业级大模型应用人才。 </dd> <dd class="cont2">343次使用</dd> </dl> </li> <li> <a href="/ai/13013.html" target="_blank" title="茅茅虫AIGC检测:精准识别AI生成内容,保障学术诚信" class="img_box"> <img src="/uploads/20250615/1749942634684e016a05088.jpg" onerror="this.onerror='',this.src='/assets/images/moren/morentu.png'" alt="茅茅虫AIGC检测:精准识别AI生成内容,保障学术诚信" style="object-fit:cover;width:100%;height:100%;"> </a> <dl> <dt class="lineTwoOverflow"><a href="/ai/13013.html" class="aBlack" target="_blank" title="茅茅虫AIGC检测">茅茅虫AIGC检测</a></dt> <dd class="cont1 lineTwoOverflow"> 茅茅虫AIGC检测,湖南茅茅虫科技有限公司倾力打造,运用NLP技术精准识别AI生成文本,提供论文、专著等学术文本的AIGC检测服务。支持多种格式,生成可视化报告,保障您的学术诚信和内容质量。 </dd> <dd class="cont2">469次使用</dd> </dl> </li> <li> <a href="/ai/13012.html" target="_blank" title="赛林匹克平台:科技赛事聚合,赋能AI、算力、量子计算创新" class="img_box"> <img src="/uploads/20250608/1749370801684547b1cedf0.jpg" onerror="this.onerror='',this.src='/assets/images/moren/morentu.png'" alt="赛林匹克平台:科技赛事聚合,赋能AI、算力、量子计算创新" style="object-fit:cover;width:100%;height:100%;"> </a> <dl> <dt class="lineTwoOverflow"><a href="/ai/13012.html" class="aBlack" target="_blank" title="赛林匹克平台(Challympics)">赛林匹克平台(Challympics)</a></dt> <dd class="cont1 lineTwoOverflow"> 探索赛林匹克平台Challympics,一个聚焦人工智能、算力算法、量子计算等前沿技术的赛事聚合平台。连接产学研用,助力科技创新与产业升级。 </dd> <dd class="cont2">571次使用</dd> </dl> </li> <li> <a href="/ai/13011.html" target="_blank" title="SEO 笔格AIPPT:AI智能PPT制作,免费生成,高效演示" class="img_box"> <img src="/uploads/20250608/17493702026845455aaeaaa.jpg" onerror="this.onerror='',this.src='/assets/images/moren/morentu.png'" alt="SEO 笔格AIPPT:AI智能PPT制作,免费生成,高效演示" style="object-fit:cover;width:100%;height:100%;"> </a> <dl> <dt class="lineTwoOverflow"><a href="/ai/13011.html" class="aBlack" target="_blank" title="笔格AIPPT">笔格AIPPT</a></dt> <dd class="cont1 lineTwoOverflow"> SEO 笔格AIPPT是135编辑器推出的AI智能PPT制作平台,依托DeepSeek大模型,实现智能大纲生成、一键PPT生成、AI文字优化、图像生成等功能。免费试用,提升PPT制作效率,适用于商务演示、教育培训等多种场景。 </dd> <dd class="cont2">481次使用</dd> </dl> </li> </ul> </div> <!-- 相关文章 --> <div class="rightContBox"> <div class="rightTit"> <a href="/articlelist.html" class="more" title="查看更多">查看更多<i class="iconfont"></i></a> <div class="tit lineOverflow">相关文章</div> </div> <ul class="aboutArticleRList"> <li> <dl> <dt class="lineTwoOverflow"><a href="/article/80964.html" class="aBlack" title="Flask框架安装技巧:让你的开发更高效">Flask框架安装技巧:让你的开发更高效</a></dt> <dd> <span class="left">2024-01-03</span> <span class="right">501浏览</span> </dd> </dl> </li> <li> <dl> <dt class="lineTwoOverflow"><a href="/article/90241.html" class="aBlack" title="Django框架中的并发处理技巧">Django框架中的并发处理技巧</a></dt> <dd> <span class="left">2024-01-22</span> <span class="right">501浏览</span> </dd> </dl> </li> <li> <dl> <dt class="lineTwoOverflow"><a href="/article/88174.html" class="aBlack" title="提升Python包下载速度的方法——正确配置pip的国内源">提升Python包下载速度的方法——正确配置pip的国内源</a></dt> <dd> <span class="left">2024-01-17</span> <span class="right">501浏览</span> </dd> </dl> </li> <li> <dl> <dt class="lineTwoOverflow"><a href="/article/113474.html" class="aBlack" title="Python与C++:哪个编程语言更适合初学者?">Python与C++:哪个编程语言更适合初学者?</a></dt> <dd> <span class="left">2024-03-25</span> <span class="right">501浏览</span> </dd> </dl> </li> <li> <dl> <dt class="lineTwoOverflow"><a href="/article/120624.html" class="aBlack" title="品牌建设技巧">品牌建设技巧</a></dt> <dd> <span class="left">2024-04-06</span> <span class="right">501浏览</span> </dd> </dl> </li> </ul> </div> </div> </div> <div class="footer"> <div class="footerIn"> <div class="footLeft"> <div class="linkBox"> <a href="/about/1.html" target="_blank" class="aBlack" title="关于我们">关于我们</a> <a href="/about/5.html" target="_blank" class="aBlack" title="免责声明">免责声明</a> <a href="#" class="aBlack" title="意见反馈">意见反馈</a> <a href="/about/2.html" class="aBlack" target="_blank" title="联系我们">联系我们</a> <a href="/send.html" class="aBlack" title="广告合作">内容提交</a> </div> <div class="footTip">Golang学习网:公益在线Go学习平台,帮助Go学习者快速成长!</div> <div class="shareBox"> <span><i class="qq"></i>技术交流群</span> </div> <div class="copyRight"> Copyright 2023 http://www.17golang.com/ All Rights Reserved | <a href="https://beian.miit.gov.cn/" target="_blank" title="备案">苏ICP备2023003363号-1</a> </div> </div> <div class="footRight"> <ul class="encodeList"> <li> <div class="encodeImg"> <img src="/assets/examples/qrcode_for_gh.jpg" alt="Golang学习网"> </div> <div class="tit">关注公众号</div> <div class="tip">Golang学习网</div> </li> <div class="clear"></div> </ul> </div> <div class="clear"></div> </div> </div> <!-- 微信登录弹窗 --> <style> .popupBg .n-error{ color: red; } </style> <div class="popupBg"> <div class="loginBoxBox"> <div class="imgbg"> <img src="/assets/images/leftlogo.jpg" alt=""> </div> <!-- 微信登录 --> <div class="loginInfo encodeLogin" style="display: none;"> <div class="closeIcon" onclick="$('.popupBg').hide();"></div> <div class="changeLoginType cursorPointer create_wxqrcode" onclick="$('.loginInfo').hide();$('.passwordLogin').show();"> <div class="tip">密码登录在这里</div> </div> <div class="encodeInfo"> <div class="tit"><i></i> 微信扫码登录或注册</div> <div class="encodeImg"> <span id="wx_login_qrcode"><img src="/assets/examples/code.png" alt="二维码"></span> <!-- <div class="refreshBox"> <p>二维码失效</p> <button type="button" class="create_wxqrcode">刷新1111</button> </div> --> </div> <div class="tip">打开微信扫一扫,快速登录/注册</div> </div> <div class="beforeLoginTip">登录即同意 <a href="#" class="aBlue" title="用户协议">用户协议</a> 和 <a href="#" class="aBlue" title="隐私政策">隐私政策</a></div> </div> <!-- 密码登录 --> <div class="loginInfo passwordLogin"> <div class="closeIcon" onclick="$('.popupBg').hide();"></div> <div class="changeLoginType cursorPointer create_wxqrcode" onclick="$('.loginInfo').hide();$('.encodeLogin').show();"> <div class="tip">微信登录更方便</div> </div> <div class="passwordInfo"> <ul class="logintabs selfTabMenu"> <li class="selfTabItem loginFormLi curr">密码登录</li> <li class="selfTabItem registerFormBox ">注册账号</li> </ul> <div class="selfTabContBox"> <div class="selfTabCont loginFormBox" style="display: block;"> <form name="form" id="login-form" class="form-vertical form" method="POST" action="/index/user/login"> <input type="hidden" name="url" value="//www.17golang.com/article/254605.html"/> <input type="hidden" name="__token__" value="1e2357ebcfc0ccc8638262fc2dd3adad" /> <div class="form-group" style="height:70px;"> <input class="form-control" id="account" type="text" name="account" value="" data-rule="required" placeholder="邮箱/用户名" autocomplete="off"> </div> <div class="form-group" style="height:70px;"> <input class="form-control" id="password" type="password" name="password" data-rule="required;password" placeholder="密码" autocomplete="off"> </div> <div class="codeBox" style="height:70px;"> <div class="form-group" style="height:70px; width:205px; float: left;"> <input type="text" name="captcha" class="form-control" placeholder="验证码" data-rule="required;length(4)" /> </div> <span class="input-group-btn" style="padding:0;border:none;"> <img src="/captcha.html" width="100" height="45" onclick="this.src = '/captcha.html?r=' + Math.random();"/> </span> </div> <div class="other"> <a href="#" class="forgetPwd aGray" onclick="$('.loginInfo').hide();$('.passwordForget').show();" title="忘记密码">忘记密码</a> </div> <div class="loginBtn mt25"> <button type="submit">登录</button> </div> </form> </div> <div class="selfTabCont registerFormBox" style="display: none;"> <form name="form1" id="register-form" class="form-vertical form" method="POST" action="/index/user/register"> <input type="hidden" name="invite_user_id" value="0"/> <input type="hidden" name="url" value="//www.17golang.com/article/254605.html"/> <input type="hidden" name="__token__" value="1e2357ebcfc0ccc8638262fc2dd3adad" /> <div class="form-group" style="height:70px;"> <input type="text" name="email" id="email2" data-rule="required;email" class="form-control" placeholder="邮箱"> </div> <div class="form-group" style="height:70px;"> <input type="text" id="username" name="username" data-rule="required;username" class="form-control" placeholder="用户名必须3-30个字符"> </div> <div class="form-group" style="height:70px;"> <input type="password" id="password2" name="password" data-rule="required;password" class="form-control" placeholder="密码必须6-30个字符"> </div> <div class="codeBox" style="height:70px;"> <div class="form-group" style="height:70px; width:205px; float: left;"> <input type="text" name="captcha" class="form-control" placeholder="验证码" data-rule="required;length(4)" /> </div> <span class="input-group-btn" style="padding:0;border:none;"> <img src="/captcha.html" width="100" height="45" onclick="this.src = '/captcha.html?r=' + Math.random();"/> </span> </div> <div class="loginBtn"> <button type="submit">注册</button> </div> </form> </div> </div> </div> <div class="beforeLoginTip">登录即同意 <a href="https://www.17golang.com/about/3.html" target="_blank" class="aBlue" title="用户协议">用户协议</a> 和 <a href="https://www.17golang.com/about/4.html" target="_blank" class="aBlue" title="隐私政策">隐私政策</a></div> </div> <!-- 重置密码 --> <div class="loginInfo passwordForget"> <div class="closeIcon" onclick="$('.popupBg').hide();"></div> <div class="returnLogin cursorPointer" onclick="$('.passwordForget').hide();$('.passwordLogin').show();">返回登录</div> <div class="passwordInfo"> <ul class="logintabs selfTabMenu"> <li class="selfTabItem">重置密码</li> </ul> <div class="selfTabContBox"> <div class="selfTabCont"> <form id="resetpwd-form" class="form-horizontal form-layer nice-validator n-default n-bootstrap form" method="POST" action="/api/user/resetpwd.html" novalidate="novalidate"> <div style="height:70px;"> <input type="text" class="form-control" id="email" name="email" value="" placeholder="输入邮箱" aria-invalid="true"> </div> <div class="codeBox" style="height:70px;"> <div class="form-group" style="height:70px; width:205px; float: left;"> <input type="text" name="captcha" class="form-control" placeholder="验证码" /> </div> <span class="input-group-btn" style="padding:0;border:none;"> <a href="javascript:;" class="btn btn-primary btn-captcha cursorPointer" style="background: #2080F8; border-radius: 4px; color: #fff; padding: 12px; position: absolute;" data-url="/api/ems/send.html" data-type="email" data-event="resetpwd">发送验证码</a> </span> </div> <input type="password" class="form-control" id="newpassword" name="newpassword" value="" placeholder="请输入6-18位密码"> <div class="loginBtn mt25"> <button type="submit">重置密码</button> </div> </form> </div> </div> </div> </div> </div> </div> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?3dc5666f6478c7bf39cd5c91e597423d"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> <script src="/assets/js/require.js" data-main="/assets/js/require-frontend.js?v=1671101972"></script> </body> </html>