本文整理汇总了Python中addon.common.net.Net.save_cookies方法的典型用法代码示例。如果您正苦于以下问题:Python Net.save_cookies方法的具体用法?Python Net.save_cookies怎么用?Python Net.save_cookies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类addon.common.net.Net
的用法示例。
在下文中一共展示了Net.save_cookies方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login_and_retry
# 需要导入模块: from addon.common.net import Net [as 别名]
# 或者: from addon.common.net.Net import save_cookies [as 别名]
def login_and_retry(redirect):
_1CH.log('Logging in for url %s' % redirect)
# needed here because login_and_retry was moved to utils. Probably better to pass in but this works and is quick but dirty.
USER_AGENT = ("User-Agent:Mozilla/5.0 (Windows NT 6.2; WOW64)"
"AppleWebKit/537.17 (KHTML, like Gecko)"
"Chrome/24.0.1312.56")
BASE_URL = _1CH.get_setting('domain')
if (_1CH.get_setting("enableDomain")=='true') and (len(_1CH.get_setting("customDomain")) > 10):
BASE_URL = _1CH.get_setting("customDomain")
user = _1CH.get_setting('username')
passwd = _1CH.get_setting('passwd')
url = BASE_URL + '/login.php'
net = Net()
cookiejar = _1CH.get_profile()
cookiejar = os.path.join(cookiejar, 'cookies')
host = re.sub('http://', '', BASE_URL)
headers = {'Referer': redirect, 'Origin': BASE_URL, 'Host': host, 'User-Agent': USER_AGENT}
form_data = {'username': user, 'password': passwd, 'remember': 'on', 'login_submit': 'Login'}
html = net.http_POST(url, headers=headers, form_data=form_data).content
if '<a href="/logout.php">[ Logout ]</a>' in html:
net.save_cookies(cookiejar)
return html
else:
_1CH.log('Failed to login')
print html
示例2: __login
# 需要导入模块: from addon.common.net import Net [as 别名]
# 或者: from addon.common.net.Net import save_cookies [as 别名]
def __login(self,redirect):
url = self.base_url + '/login.php'
net = Net()
cookiejar = _1CH.get_profile()
cookiejar = os.path.join(cookiejar, 'cookies')
host = re.sub('http://', '', self.base_url)
headers = {'Referer': redirect, 'Origin': self.base_url, 'Host': host, 'User-Agent': USER_AGENT}
form_data = {'username': self.username, 'password': self.password, 'remember': 'on', 'login_submit': 'Login'}
html = net.http_POST(url, headers=headers, form_data=form_data).content
if '<a href="/logout.php">[ Logout ]</a>' in html:
net.save_cookies(cookiejar)
return True
else:
return False
示例3: request
# 需要导入模块: from addon.common.net import Net [as 别名]
# 或者: from addon.common.net.Net import save_cookies [as 别名]
def request(self, uri, params=None, query=None, headers=None, return_soup=False, return_json=False):
COOKIE_JAR = vfs.join(COOKIE_PATH, self.service + ".lwp")
net = Net()
net.set_cookies(COOKIE_JAR)
if headers:
headers["Referer"] = self.referrer
headers["Accept"] = self.ACCEPT
headers["User-Agent"] = self.USER_AGENT
else:
headers = {"Referer": self.referrer, "Accept": self.ACCEPT, "User-Agent": self.USER_AGENT}
if query:
uri = uri % urllib.urlencode(query)
if params:
html = net.http_POST(self.base_url + uri, params, headers=headers).content
else:
html = net.http_GET(self.base_url + uri, headers=headers).content
net.save_cookies(COOKIE_JAR)
if return_soup:
return BeautifulSoup(html)
elif return_json:
return json.loads(html)
else:
return html