-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_cookies.py
48 lines (42 loc) · 1.37 KB
/
test_cookies.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# coding:utf-8
from login import login_sina
from selenium.common.exceptions import WebDriverException
from selenium import webdriver
import time
from pprint import pprint
import basic
"""
test cookies
"""
def test_cookies(cookies, url):
useful_cookie = []
print('There are %d cookies in the list' %(len(cookies)))
for index, cookie in enumerate(cookies):
print('Start test NO.%d cookie' %(index))
print('''The name of cookie: %s
The value of cookie: %s''' %(cookie['name'], cookie['value']))
try:
print('initiate PhantomJS...')
driver = webdriver.PhantomJS()
print('add cookie...')
driver.add_cookie(cookie)
except WebDriverException:
print('can not load this cookie into driver!')
finally:
driver.get(url)
time.sleep(12)
if basic.is_login(driver.page_source):
print('Login successful!')
useful_cookie.append(cookie)
else:
print('Login failure!')
driver.delete_all_cookies()
driver.close()
time.sleep(5)
return useful_cookie
if __name__ == '__main__':
print('starting get cookies')
owner = 'xie'
cookies = login_sina(owner, basic.LOGIN_URL)
useful_cookies = test_cookies(cookies, basic.LOGIN_URL)
pprint(useful_cookies)