使用 urllib2.Request(url) 和 BeautifulSoup 返回以下内容:
<?xml version="1.0" encoding="utf-8"?>
<results>
<status code="ok">
</status>
<principal-list>
<principal account-id="1013353221" has-children="false" is-hidden="false" is-primary="false" principal-id="1013353225" training-group-id="" type="user">
<name>
First Last
</name>
<login>
first.last
</login>
<email>
first.last@domain.com
</email>
<display-uid>
first.last
</display-uid>
</principal>
<principal account-id="1013353221" has-children="false" is-hidden="false" is-primary="false" principal-id="1115269931" training-group-id="" type="user">
<name>
First Last
</name>
<login>
first.last
</login>
<email>
first.last@domain.com
</email>
<display-uid>
first.last
</display-uid>
</principal>
</principal-list>
</results>
这就是我要返回您在上面看到的列表的方法:
req = urllib2.Request(url)
response = urllib2.urlopen(req)
userlist = response.read()
soup = BeautifulSoup(userlist)
print(soup.prettify())
我想打电话username = sys.argv[1]
并让它返回principal-id
包含username
在<login> </login>