selenium保存cookie

selenium利用浏览器保存cookie

def make_cookie(item):
    return http.cookiejar.Cookie(
        version=0,
        name=item['name'],
        value=item['value'],
        port=None,
        port_specified=False,
        domain="jd.com",
        domain_specified=True,
        domain_initial_dot=False,
        path="/",
        path_specified=True,
        secure=False,
        expires=None,
        discard=False,
        comment=None,
        comment_url=None,
        rest=None
    )

scookie = driver.get_cookies()
for item in scookie:
    cookie.set_cookie(make_cookie(item))
with open("cookies.txt", "w") as fp:
    json.dump(scookie, fp)
driver.close()

selenium保存cookie:等您坐沙发呢!

发表评论

表情
还能输入210个字