how to remove an element in lxml
import lxml.etree as et xml="""
<groceries>
<fruit state="rotten">apple</fruit>
<fruit state="fresh">pear</fruit>
<punnet>
<fruit state="rotten">strawberry</fruit>
<fruit state="fresh">blueberry</fruit>
</punnet>
<fruit state="fresh">starfruit</fruit>
<fruit state="rotten">mango</fruit>
<fruit state="fresh">peach</fruit>
</groceries>
""" tree=et.fromstring(xml) for bad in tree.xpath("//fruit[@state='rotten']"):
bad.getparent().remove(bad) print et.tostring(tree, pretty_print=True)
how to remove an element in lxml的更多相关文章
- [CodeForces - 1272D] Remove One Element 【线性dp】
[CodeForces - 1272D] Remove One Element [线性dp] 标签:题解 codeforces题解 dp 线性dp 题目描述 Time limit 2000 ms Me ...
- Codeforces Round #605 (Div. 3) D. Remove One Element(DP)
链接: https://codeforces.com/contest/1272/problem/D 题意: You are given an array a consisting of n integ ...
- CF1272D. Remove One Element 题解 动态规划
题目链接:http://codeforces.com/contest/1272/problem/D 题目大意: 给你一个长度为 \(n\) 的数组,你最多删除一个元素(也可以不删),求此条件限制下的最 ...
- jQuery之empty、remove、detach
三者都有把元素移除的作用,但细微的差别,造就了它们的使命不同. 最权威的解释当然是jQuery_API咯,下面是API中关于他三儿的部分截取. 一.empty: This method removes ...
- 402. Remove K Digits
(English version is after the code part) 这个题做起来比看起来容易,然后我也没仔细想,先速度刷完,以后再看有没有改进. 用这个来说: 1 2 4 3 2 2 1 ...
- [Swift]LeetCode703. 数据流中的第K大元素 | Kth Largest Element in a Stream
Design a class to find the kth largest element in a stream. Note that it is the kth largest element ...
- Jquery empty() remove() detach() 方法的区别
方法简介: empty() This method removes not only child (and other descendant) elements, but also any text ...
- jQuery object and DOM Element
They're both objects but DOMElements are special objects. jQuery just wraps DOMElements in a Javascr ...
- Codeforces 900C. Remove Extra One(暴力)
You are given a permutation p of length n. Remove one element from permutation to make the number of ...
随机推荐
- Navicat oracle to postgresql ERR
可能的解决思路是设好源数据和目标数据库后,先建立表结构,然后修改表结构字段数据类型 参考 https://www.cnblogs.com/stephen-liu74/archive/2012/04/3 ...
- nohup追加日志
背景:用脚本部署Spring Boot应用,用nohup命令进行后台运行 之前的日志处理: nohup command > myout.file 2>&1 & 导致每次用s ...
- 并查集——poj2236(带权并查集)
题目:Wireless Network 题意:给定n台已损坏计算机的位置和计算机最远通信距离d,然后分别根据命令执行以下两种操作: "O p" (1 <= p <= N ...
- 正则匹配java多行注释
类似: /** * This method was generated by MyBatis Generator. * This method returns the value of the dat ...
- WIN8/8.1/10换系统常见的几个问题
1.如果高级选项中没有UEFI固件设置,这该怎么进入BIOS呢? 答:还有一种方法是,首先关闭快速启动,然后重启,开机画面出来之后按F1,F2,F12,delete,总有一个是对的(不确定的话可以四个 ...
- PAT 1055 集体照
https://pintia.cn/problem-sets/994805260223102976/problems/994805272021680128 拍集体照时队形很重要,这里对给定的 N 个人 ...
- 绝对定位后a、button等hover状态样式不显示问题
<div class="operate"> <el-button>提交项目</el-button> <el-button type=&qu ...
- Java IO 之 RandomAccessFile 操作文件内容
RandomAccessFile类实现对文件内容的随机读写 文件内容的随机操作,重难点在于字符操作,具体查看API package org.zln.io.file; import java.io.IO ...
- 安装与配置JDK
第一步:下载jdk-7-linux-i586.tar.gzwget -c http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-i586. ...
- 高中信息技术《算法与程序设计VB(选修)》知识要点
原博主: http://blog.sina.com.cn/buyanshibai [转载] (一)算法 1.定义 相关题解: 1算法:就是解决问题的方法和步骤.算法是程序设计的“灵魂”,算法+数据结构 ...