阅读(1141) (31)

selenium2 使用Cookies

2021-06-22 15:46:16 更新

在我们进行下一步之前,你可能会好奇如何使用​cookie​,首先你需要处在一个域名下,然后这样设置​cookie​:

# Go to the correct domain
driver.get("http://example.com")

# Now set the cookie. This one's valid for the entire domain
cookie = {'name':'foo','value':'bar'}
driver.add_cookie(cookie)

# And now output all the available cookies for the current URL
driver.get_cookies()