[英]How can I parse XML file which ask for credentials in python
Can someone help here, I want to parse a XML file which asks for authentication(user, password) but with my code.
有人可以在这里提供帮助吗,我想解析一个 XML 文件,该文件要求使用我的代码进行身份验证(用户,密码)。 Can someone help what should I use or edit in my code so that my code can parse svn https link?
有人可以帮助我在代码中使用或编辑什么,以便我的代码可以解析 svn https 链接吗?
import urllib.request as url
import xml.etree.ElementTree as ET
xmlfile=url.urlopen(r'file:///D:/Python/user.html')
def fileparse(xmlfile):
tree=ET.parse(xmlfile)
root=tree.getroot()
#print(root.tag)
users={root.get("name"):[]}
for item in root.findall("client"):
users[root.get("name")].append(item.get("name"))
return users
k1=input("user or client, please mention:")
if k1=='user':
k10=input("Enter the user id you want to search for:")
d1=fileparse(xmlfile)
for k,v in d1.items():
if k==k10:
print(k,v)
elif k1=='client':
c10=input("Enter the client name you want to search for:")
d1=fileparse(xmlfile)
for k,v in d1.items():
if c10 in v:
print(k)
else:
print("sorry please check your input values")
I think there is indentation wrong in your code.我认为您的代码中有缩进错误。
users and for loop should be present inside function to execute. users 和 for 循环应该出现在 function 中才能执行。
import urllib.request as url
import xml.etree.ElementTree as ET
xmlfile = url.urlopen(r'file:///D:/Python/user.html').read()
def fileparse(xmlfile):
tree = ET.parse(xmlfile)
root = tree.getroot()
# print(root.tag)
users = {root.get("name"): []}
for item in root.findall("client"):
users[root.get("name")].append(item.get("name"))
return users
print(fileparse(xmlfile))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.