當前位置: 首頁>>代碼示例>>Python>>正文


Python cookiejar.LWPCookieJar方法代碼示例

本文整理匯總了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 
開發者ID:sk364,項目名稱:codechef-cli,代碼行數:18,代碼來源:decorators.py

示例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 
開發者ID:Andargor,項目名稱:edce-client,代碼行數:18,代碼來源:query.py

示例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 
開發者ID:KANG-NEWBIE,項目名稱:s-mbf,代碼行數:21,代碼來源:Genkuki.py

示例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() 
開發者ID:KANG-NEWBIE,項目名稱:s-mbf,代碼行數:25,代碼來源:Genkuki.py

示例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') 
開發者ID:KANG-NEWBIE,項目名稱:s-mbf,代碼行數:22,代碼來源:Cspam.py

示例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) 
開發者ID:KANG-NEWBIE,項目名稱:s-mbf,代碼行數:23,代碼來源:Cspam.py

示例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') 
開發者ID:lb2281075105,項目名稱:Python-Spider,代碼行數:19,代碼來源:18 github_login.py

示例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 
開發者ID:IgnoredAmbience,項目名稱:yahoo-group-archiver,代碼行數:19,代碼來源:yahoo.py

示例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') 
開發者ID:zkqiang,項目名稱:zhihu-login,代碼行數:25,代碼來源:zhihu_login.py

示例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 
開發者ID:x1ah,項目名稱:Daily_scripts,代碼行數:18,代碼來源:baidu_count_login.py

示例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) 
開發者ID:sk364,項目名稱:codechef-cli,代碼行數:4,代碼來源:helpers.py

示例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() 
開發者ID:openSUSE,項目名稱:openSUSE-release-tools,代碼行數:12,代碼來源:obs_operator.py

示例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 
開發者ID:gautamkrishnar,項目名稱:socli,代碼行數:37,代碼來源:auth.py

示例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 
開發者ID:gautamkrishnar,項目名稱:socli,代碼行數:16,代碼來源:auth.py

示例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 
開發者ID:gautamkrishnar,項目名稱:socli,代碼行數:31,代碼來源:auth.py


注:本文中的http.cookiejar.LWPCookieJar方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。