from urllib import request,parse
from urllib.error import HTTPError,URLError
from http import cookiejar
class Session(object):
def __init__(self):
cookie_obj = cookiejar.CookieJsr()
handler = request.HTTPCookieProcessor(cookie_obj)
self.opener = request.build_opener(handler)
def get(self,url,headers=None):
return get(url,headers,self.opener)
def post(self,url,form,headers=None):
return post(url,form,headers,self.opener)
def get(url,headers=None,opener=None):
return urlrequests(url,headers=headers,opener=opener)
def post(url,form,headers=None,opener=None):
return urlrequests(url,form,hraders=headers,opener=opener)
def urlrequests(url,form=None,headers=None,opener=None):
user_agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'
# 如果用户需要自行传入headers, 则覆盖之前的headers
if