mechanize python XE #7
def HTTPcode(self):
try:
if self.agent == True:
br = Browser()
UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0"
header = {"User-Agent" : UserAgent}
br.set_handle_robots(False)
br.addheaders = [("User-agent", "Fifefox")]
resp = br.open(self.target).code
else:
resp = u.urlopen(self.target).getcode()
return(resp)
except (u.HTTPError, u.URLError):
return(404)