AttributeError:没有这样的子级:Lxml objectify

2024-04-26 04:52:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从KML文件中提取坐标。但是,我一直得到这个错误:

for e in doc.Document.Folder.Placemark:
  File "src\lxml\objectify.pyx", line 230, in lxml.objectify.ObjectifiedElement.__getattr__
  File "src\lxml\objectify.pyx", line 450, in lxml.objectify._lookupChildOrRaise
AttributeError: no such child: {http://www.opengis.net/kml/2.2}Placemark

我提取坐标的代码如下:

^{pr2}$

不完全确定该怎么做或如何修复它。在

编辑:这是我的kml文件的第一位。我对Python也很陌生,所以我不太了解attributes和children之类的东西。谢谢你,谢谢。在

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <name>loc</name>
    <description/>
    <Style id="poly-000000-1200-77-nodesc-normal">
      <LineStyle>

这就是:

 <Folder>
      <name>Untitled layer</name>
      <Placemark>
        <name>loc</name>
        <styleUrl>#poly-000000-1200-77-nodesc</styleUrl>
        <Polygon>
          <outerBoundaryIs>
            <LinearRing>
              <tessellate>1</tessellate>
              <coordinates>
                -1.0947725,53.9600505,0
                -1.0967252,53.95697,0
                -1.0909316,53.9562629,0
                -1.0887214,53.9598864,0
                -1.0947725,53.9600505,0
              </coordinates>
            </LinearRing>
          </outerBoundaryIs>
        </Polygon>
      </Placemark>
    </Folder>

Tags: 文件nameinsrchttpwwwlinefolder