python http认证

2023-01-31 01:01:38 python http 认证
#!/usr/bin/env python

import urllib2
import re
# this creates a passWord manager
url='Http://test/nagiOS/cgi-bin/status.cgi?host=all'
User='admin'
Pass='123'
paSSMan = urllib2.HTTPPasswordMgrWithDefaultRealm()    
passman.add_password(None, url, User, Pass)
# create the AuthHandler
authhandler = urllib2.HTTPBasicAuthHandler(passman)    
opener = urllib2.build_opener(authhandler)    
urllib2.install_opener(opener)
pagehandle = urllib2.urlopen(url)
data = pagehandle.read()
pagehandle.close()
f=re.search('.*load .*',data)
x=f.group()

相关文章