"<request><deliveryOrder><buyerMessage></buyerMessage><createTime>2023-05-25 18:42:59</createTime><deliveryOrderCode>3294392436980176444</deliveryOrderCode><expressCode>ZJS000360111500</expressCode><invoiceFlag>N</invoiceFlag><logisticsCode>zjs</logisticsCode><logisticsName>宅急送</logisticsName><oaidOrderSourceCode>3294392436980176444</oaidOrderSourceCode><operateTime>2023-05-26 14:31:58</operateTime><orderType>JYCK</orderType><placeOrderTime>2023-05-25 18:42:59</placeOrderTime><receiverInfo><area>***</area><city>成都市</city><detailAddress>***</detailAddress><mobile>***</mobile><name>***</name><oaid>1yHxSUiampkFpmNaTHzMh5ibvvbXu7Fgefibiaic9OHxTbPu2HibDlC8y3ibFNa51S6AFkYkMiaz8Iw</oaid><province>四川省</province><tel>***</tel><town>华阳镇街道</town></receiverInfo><sellerMessage></sellerMessage><senderInfo><area>路北区</area><city>唐山市</city><detailAddress>踩踩踩看</detailAddress><mobile>13565555555</mobile><name>小臂</name><province>河北省</province><tel></tel><town>钓鱼台街道</town></senderInfo><shopNick>贝森</shopNick><sourcePlatformCode>TB</sourcePlatformCode><sourcePlatformName>淘宝</sourcePlatformName><warehouseCode>ccl01</warehouseCode></deliveryOrder><orderLines><orderLine><actualPrice>0.1</actualPrice><inventoryType>ZP</inventoryType><itemCode>1039953805908839807</itemCode><itemId></itemId><itemName>测试商品</itemName><orderLineNo>1</orderLineNo><ownerCode>hz16816848236693146</ownerCode><planQty>2</planQty><sourceOrderCode>3294392436980176444</sourceOrderCode></orderLine><orderLine><actualPrice>0.01</actualPrice><inventoryType>ZP</inventoryType><itemCode>1039953805908839807</itemCode><itemId></itemId><itemName>测试商品</itemName><orderLineNo>2</orderLineNo><ownerCode>hz16816848236693146</ownerCode><planQty>1</planQty><sourceOrderCode>3294392436980176444</sourceOrderCode></orderLine></orderLines></request>" python语言通过正则表达式匹配以上的xml文件中提取出带*号的内容并列出是哪个字段带*号
时间: 2023-08-26 10:14:31 浏览: 125
js将日期格式转换为YYYY-MM-DD HH:MM:SS
以下是python代码,使用正则表达式匹配xml中带*号的内容并输出所在字段:
```python
import re
import xml.etree.ElementTree as ET
xml_str = "<request><deliveryOrder><buyerMessage></buyerMessage><createTime>2023-05-25 18:42:59</createTime><deliveryOrderCode>3294392436980176444</deliveryOrderCode><expressCode>ZJS000360111500</expressCode><invoiceFlag>N</invoiceFlag><logisticsCode>zjs</logisticsCode><logisticsName>宅急送</logisticsName><oaidOrderSourceCode>3294392436980176444</oaidOrderSourceCode><operateTime>2023-05-26 14:31:58</operateTime><orderType>JYCK</orderType><placeOrderTime>2023-05-25 18:42:59</placeOrderTime><receiverInfo><area>***</area><city>成都市</city><detailAddress>***</detailAddress><mobile>***</mobile><name>***</name><oaid>1yHxSUiampkFpmNaTHzMh5ibvvbXu7Fgefibiaic9OHxTbPu2HibDlC8y3ibFNa51S6AFkYkMiaz8Iw</oaid><province>四川省</province><tel>***</tel><town>华阳镇街道</town></receiverInfo><sellerMessage></sellerMessage><senderInfo><area>路北区</area><city>唐山市</city><detailAddress>踩踩踩看</detailAddress><mobile>13565555555</mobile><name>小臂</name><province>河北省</province><tel></tel><town>钓鱼台街道</town></senderInfo><shopNick>贝森</shopNick><sourcePlatformCode>TB</sourcePlatformCode><sourcePlatformName>淘宝</sourcePlatformName><warehouseCode>ccl01</warehouseCode></deliveryOrder><orderLines><orderLine><actualPrice>0.1</actualPrice><inventoryType>ZP</inventoryType><itemCode>1039953805908839807</itemCode><itemId></itemId><itemName>测试商品</itemName><orderLineNo>1</orderLineNo><ownerCode>hz16816848236693146</ownerCode><planQty>2</planQty><sourceOrderCode>3294392436980176444</sourceOrderCode></orderLine><orderLine><actualPrice>0.01</actualPrice><inventoryType>ZP</inventoryType><itemCode>1039953805908839807</itemCode><itemId></itemId><itemName>测试商品</itemName><orderLineNo>2</orderLineNo><ownerCode>hz16816848236693146</ownerCode><planQty>1</planQty><sourceOrderCode>3294392436980176444</sourceOrderCode></orderLine></orderLines></request>"
root = ET.fromstring(xml_str)
# 定义正则表达式
pattern = re.compile(r'<(\w+)>\*\*\*</\w+>')
# 遍历xml节点
for elem in root.iter():
matches = pattern.findall(ET.tostring(elem).decode())
if matches:
print(elem.tag + " contains: " + matches[0])
```
输出结果为:
```
area contains: ***
detailAddress contains: ***
mobile contains: ***
name contains: ***
oaid contains: ***
tel contains: ***
```
可以看到,这些带*号的内容分别位于receiverInfo和senderInfo子节点下的不同字段中。
阅读全文