Python学习:获取标签属性,,文件info.xml
Python学习:获取标签属性,,文件info.xml
文件info.xml
<?xmlversion="1.0"encoding="utf-8"?><info><base><platform>Windows</platform><browser>Firefox</browser><url>http://www.baidu.com</url><loginusername="admin"password="123456"/><loginusername="guest"password="654321"/></base><test><province>北京</province><province>广东</province><city>深圳</city><city>珠海</city><province>浙江</province><city>杭州</city></test></info>
文件read_xml_1.py:获取任意标签名
#coding=utf-8importxml.dom.minidomdom=xml.dom.minidom.parse(‘E:\\Selenium_Relatived\\learning\\info.xml‘)root=dom.documentElementprint(root.nodeName)tagname=root.getElementsByTagName(‘browser‘)print(tagname[0].tagName)tagname1=root.getElementsByTagName(‘login‘)print(tagname1[1].tagName)tagname2=root.getElementsByTagName(‘province‘)print(tagname2[2].tagName)
getElementsByTagName通过标签名获取标签,它所获得的对象是以数组形式存放
2.文件read_xml_2.py:获取标签的属性
#coding=utf-8importxml.dom.minidomdom=xml.dom.minidom.parse(‘E:\\Selenium_Relatived\\learning\\info.xml‘)root=dom.documentElementprint(root.nodeName)logins=root.getElementsByTagName(‘login‘)username=logins[0].getAttribute(‘username‘)print(username)username1=logins[1].getAttribute(‘username‘)print(username1)
3.获取标签对之间的数据
#coding=utf-8importxml.dom.minidomdom=xml.dom.minidom.parse(‘E:\\Selenium_Relatived\\learning\\info.xml‘)root=dom.documentElementprint(root.nodeName)province=dom.getElementsByTagName(‘province‘)citys=dom.getElementsByTagName(‘city‘)p2=province[1].firstChild.dataprint(p2)c1=citys[0].firstChild.dataprint(c1)
Python学习:获取标签属性
相关内容
- Python自动化学习--控制浏览器,,from selen
- Python实现H5页面,,1 from sel
- python+selenium 点击单选框-radio的实现方法,
- selenium+python 爬取网络图片(2) -- 百度,,上一篇博文介绍
- selenium+python环境配置教程详解,seleniumpython
- python自动化脚本初学记录之句柄切换(1),python句柄
- python使用selenium实现批量文件下载,
- Python爬虫之selenium库使用详解,python爬虫selenium,Seleniu
- 使用Python学习selenium测试工具,pythonselenium,Selenium的组件
- Python2和Python3共存安装robotframework,,1、下载Python
评论关闭