详情参考这里,下面提供核心代码。
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
|
#coding=utf-8
#author:walker
#date:2013-11-21
from
selenium
import
webdriver
import
time
import
requests
b
=
webdriver.Firefox()
#b = webdriver.Ie()
b.delete_all_cookies()
cookies
=
{}
while
True
:
list_cookies
=
b.get_cookies()
#这里返回的是一个更多信息的字典列表
print
(list_cookies)
for
s
in
list_cookies:
cookies[s[
'name'
]]
=
s[
'value'
]
print
(cookies)
if
cookies.has_key(
'BAIDUID'
):
b.close()
break
time.sleep(
2
)
sn
=
requests.Session()
requests.utils.add_dict_to_cookiejar(sn.cookies, cookies)
#或者
requests.get(url, cookies
=
cookies)
|
相关阅读:
1、Cookies揭秘 [Asp.Net, Javascript]
3、How to add a cookie to the cookiejar in python requests library
*** walker ***
本文转自walker snapshot博客51CTO博客,原文链接http://blog.51cto.com/walkerqt/1329600如需转载请自行联系原作者
RQSLT