import requests
class HttpRequestA:
def __init__(self,url,data):
self.url=url
self.data=data
def get_request(self):
res=requests.get(self.url,self.data)
print("这是一个get请求",res)
def post_request(self):
res=requests.post(self.url,self.data)
print("这里是一个post请求",res)
def print_praction(self):
print("测试一下")
class HttpRequestB(HttpRequestA):
def __init__(self,method,url,data): #超继承,保留父类的方法,对自己现在的类进行改造
super(HttpRequestB,self).__init__(url,data) #super(子类名称,self).调用父类相同的方法(参数),有参数就传参数,无参就不传
self.method=method
def Method(self):
if self.method=='get':
self.get_request() #调用父类里面的get和post请求
else:
self.post_request()
def print_msg(self):
self.print_praction() #self.属性或者是方法 self.方法
print("继承上面一个类的,这个类是子类特有的,需要传参吗?当然需要啊")
def print_praction(self):
print("父类方法名称和子类相同,叫做重写,重写之后,用子类的方法")
url="https://passport.jd.com/new/login.aspx?ReturnUrl=https%3A%2F%2Fwww.jd.com%2F%3Fcu%3Dtrue%26utm_source%3Dbaidu-pinzhuan%26utm_medium%3Dcpc%26utm_campaign%3Dt_288551095_baidupinzhuan%26utm_term%3D0f3d30c8dba7459bb52f2eb5eba8ac7d_0_93b9bee5df38406382d2ea793e21c38b"
data={"phone":"133333333333","pwd":"123456"}
HttpRequestB('get',url,data).Method()