Python SVG解析器 [英] Python SVG parser

查看:143
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆