Python SVG 解析器 [英] Python SVG parser
本文介绍了Python SVG 解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用 python 解析 SVG 文件以提取坐标/路径(我相信这列在路径"ID 下,特别是 d="..."/>).这些数据最终将用于驱动 2 轴 CNC.
I want to parse an SVG file using python to extract coordinates/paths (I believe this is listed under the "path" ID, specifically the d="..."/>). This data will eventually be used to drive a 2 axis CNC.
我在 SO 和 Google 上搜索了可以返回此类路径字符串的库,以便我可以进一步解析它,但无济于事.有这样的库吗?
I've searched on SO and Google for libraries that can return the string of such paths so I can further parse it, but to no avail. Does such a library exist?
推荐答案
忽略变换,你可以像这样从 SVG 中提取路径字符串:
Ignoring transforms, you can extract the path strings from an SVG like so:
from xml.dom import minidom
doc = minidom.parse(svg_file) # parseString also exists
path_strings = [path.getAttribute('d') for path
in doc.getElementsByTagName('path')]
doc.unlink()
这篇关于Python SVG 解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文