本文整理汇总了Python中http.cookiejar.LWPCookieJar方法的典型用法代码示例。如果您正苦于以下问题:Python cookiejar.LWPCookieJar方法的具体用法?Python cookiejar.LWPCookieJar怎么用?Python cookiejar.LWPCookieJar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类http.cookiejar
的用法示例。
在下文中一共展示了cookiejar.LWPCookieJar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login_required
# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import LWPCookieJar [as 别名]
def login_required(func):
@wraps(func)
def wrapper(*args, **kwargs):
is_logged_in = False
if os.path.exists(COOKIES_FILE_PATH):
cookiejar = LWPCookieJar(filename=COOKIES_FILE_PATH)
cookiejar.load()
if len(cookiejar):
is_logged_in = True
else:
os.remove(COOKIES_FILE_PATH)
if is_logged_in is False:
return [{'code': 401}]
return func(*args, **kwargs)
return wrapper
示例2: initSession
# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import LWPCookieJar [as 别名]
def initSession():
if edce.globals.debug:
print(">>>>>>>>>>>>>>>> initSession")
cookie_filename = edce.config.getString('paths','cookie_file')
session = requests.Session()
session.headers['User-Agent'] = 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D257'
session.cookies = LWPCookieJar(cookie_filename)
try:
session.cookies.load(ignore_discard=True)
except FileNotFoundError:
session.cookies.save()
return session
示例3: cek
# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import LWPCookieJar [as 别名]
def cek():
try:
s.cookies=kuki('toket/kue.txt')
s.cookies.load()
cek=s.get('https://mbasic.facebook.com/me').text
if 'mbasic_logout_button' in cek:
print('[√] cookies valids\n')
a='True'
return a
else:
print('[!] cookies invalid')
os.remove('toket/kue.txt')
a='False'
return a
except:
print('[!] cookies invalid')
os.remove('toket/kue.txt')
a='False'
return a
示例4: login
# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import LWPCookieJar [as 别名]
def login(self):
global s
print("\n[!] checking cookies")
time.sleep(1)
s = self.req
s.cookies = kuki('toket/kue.txt')
try:
fil=open('toket/kue.txt')
fil.close()
except FileNotFoundError:
print("[!] cookies not found\n\n[!] please login in your facebook once again")
email=input('[?] email/username: ')
pw=prompt('[?] password: ', is_password=True)
data = {'email':email,'pass':pw}
res = s.post('https://mbasic.facebook.com/login',data=data).text
if 'logout.php' in str(res) or 'mbasic_logout_button' in str(res):
s.cookies.save()
else:
exit('[!] fail login into your account')
if 'True' in cek():
pass
else:
exit()
示例5: login
# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import LWPCookieJar [as 别名]
def login():
print("\n[!] checking cookies")
time.sleep(1)
s = ses()
s.cookies = kuki('toket/kue.txt')
try:
fil=open('toket/kue.txt')
fil.close()
except FileNotFoundError:
print("[!] cookies not found\n\n[!] please login in your facebook once again")
email=input('[?] email/username: ')
pw=prompt('[?] password: ',is_password=True)
data = {'email':email,'pass':pw}
url='https://mbasic.facebook.com/login'
res = s.post(url,data=data).text
if 'logout.php' in str(res) or 'mbasic_logout_button' in str(res):
s.cookies.save()
else:
exit('[!] fail login into your account')
示例6: send
# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import LWPCookieJar [as 别名]
def send(id,msg,lop):
try:
print()
cjs = kuki('toket/kue.txt')
cjs.load()
br.set_cookiejar(cjs)
for i in range(int(lop)):
print("[!] sending messages to "+id)
br.open('https://mbasic.facebook.com/messages/thread/'+id+'/')
br.form = list(br.forms())[1]
control = br.form.find_control("body")
for control in br.form.controls:
if control.type == "submit":
control.disabled = True
br["body"]=msg
snd=br.submit().read()
if 'send_success' in str(snd):
print('[+] succes')
else: print('[-] failed')
except IndexError:
print("[!] error when sending a message to",id)
示例7: __init__
# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import LWPCookieJar [as 别名]
def __init__(self):
# url
self.loginUrl = 'https://github.com/login'
self.postUrl = 'https://github.com/session'
self.profileUrl = 'https://github.com/settings/profile'
# 设置请求头
self.headers = {
'Referer': 'https://github.com/',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36',
'Host': 'github.com'
}
# 设置session
self.session = requests.session()
# 生成github_cookie文件
self.session.cookies = cookielib.LWPCookieJar(filename='github_cookie')
示例8: init_cookie_jar
# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import LWPCookieJar [as 别名]
def init_cookie_jar(cookie_file=None, cookie_t=None, cookie_y=None, cookie_euconsent=None):
cookie_jar = LWPCookieJar(cookie_file) if cookie_file else RequestsCookieJar()
if cookie_file and os.path.exists(cookie_file):
cookie_jar.load(ignore_discard=True)
if args.cookie_t:
cookie_jar.set_cookie(create_cookie('T', cookie_t))
if cookie_y:
cookie_jar.set_cookie(create_cookie('Y', cookie_y))
if cookie_euconsent:
cookie_jar.set_cookie(create_cookie('EuConsent', cookie_euconsent))
if cookie_file:
cookie_jar.save(ignore_discard=True)
return cookie_jar
示例9: __init__
# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import LWPCookieJar [as 别名]
def __init__(self, username: str = None, password: str = None):
self.username = username
self.password = password
self.login_data = {
'client_id': 'c3cef7c66a1843f8b3a9e6a1e3160e20',
'grant_type': 'password',
'source': 'com.zhihu.web',
'username': '',
'password': '',
'lang': 'en',
'ref_source': 'other_https://www.zhihu.com/signin?next=%2F',
'utm_source': ''
}
self.session = requests.session()
self.session.headers = {
'accept-encoding': 'gzip, deflate, br',
'Host': 'www.zhihu.com',
'Referer': 'https://www.zhihu.com/',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '
'(KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36'
}
self.session.cookies = cookiejar.LWPCookieJar(filename='./cookies.txt')
示例10: get_cookies
# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import LWPCookieJar [as 别名]
def get_cookies():
"""获取百度 cookies, 并写入文件."""
headers = {
"User-Agent": (
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36"
"(KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36"
)
}
save_cookies_file = 'cookies.txt'
jar = cookielib.LWPCookieJar(save_cookies_file)
sess = requests.session()
sess.headers = headers
sess.cookies = jar
sess.get('http://tieba.baidu.com/')
jar.save(ignore_expires=True, ignore_discard=True)
return jar
示例11: set_session_cookies
# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import LWPCookieJar [as 别名]
def set_session_cookies(session):
session.cookies = LWPCookieJar(filename=COOKIES_FILE_PATH)
示例12: cookiejar_create
# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import LWPCookieJar [as 别名]
def cookiejar_create(self, cookiejar_file, session):
cookie_jar = LWPCookieJar(cookiejar_file.name)
cookie_jar.set_cookie(Cookie(0, self.COOKIE_NAME, session,
None, False,
'', False, True,
'/', True,
True,
None, None, None, None, {}))
cookie_jar.save()
cookiejar_file.flush()
示例13: login_required
# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import LWPCookieJar [as 别名]
def login_required(func):
"""
:desc: decorator method to check user's login status
"""
@wraps(func)
def wrapper(*args, **kwargs):
"""
:desc: Wrapper to check if user is logged in, if the
stored cookies contain cookie named `acct`
and is not expired.
"""
is_login = False
resp = {'success': False, 'message': 'You are not logged in!'}
if os.path.exists(COOKIES_FILE_PATH):
cookiejar = LWPCookieJar(filename=COOKIES_FILE_PATH)
cookiejar.load()
for cookie in cookiejar:
if cookie.name == 'acct':
expiry_time_obj = datetime.utcfromtimestamp(cookie.expires)
if datetime.now() > expiry_time_obj:
is_login = True
if not is_login:
os.remove(COOKIES_FILE_PATH)
else:
return func(*args, **kwargs)
return resp
return wrapper
示例14: get_session
# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import LWPCookieJar [as 别名]
def get_session():
"""
:desc: Builds session from the saved cookies, if present.
Otherwise, a new session is created.
:return: requests.Session object
"""
session = Session()
if os.path.exists(COOKIES_FILE_PATH):
session.cookies = LWPCookieJar(filename=COOKIES_FILE_PATH)
session.cookies.load(ignore_discard=True, ignore_expires=True)
return session
示例15: login
# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import LWPCookieJar [as 别名]
def login(email, password):
"""
:desc: Logs a user in.
:param: email - Email of the user - required
password - Password of the user - required
:return: `dict`
"""
if email == '' or password == '':
return {'success': False, 'message': 'Email/Password field left blank.'}
resp = {'success': False}
data = {'email': email, 'password': password}
session = get_session()
session.cookies = LWPCookieJar(filename=COOKIES_FILE_PATH)
resp_obj = session.post(LOGIN_URL, data=data)
if resp_obj.status_code == 200:
if resp_obj.url == BASE_URL:
session.cookies.save(ignore_expires=True, ignore_discard=True)
resp['success'] = True
resp['message'] = 'Successfully Logged In!'
else:
resp['message'] = 'Incorrect credentials'
else:
resp['message'] = 'Stackoverflow is probably down. Please try again.'
return resp