Python_获取cookie

获取cookie

from selenium import webdriver
from selenium.webdriver.common.by import By # 定位
from selenium.webdriver.support.ui import WebDriverWait #显性等待库
import time
driver = webdriver.Chrome()



bbs_url='http://bbs.fengniao.com/forum/forum_30.html'
def cookie_login(bbs_url, account='test00001', password='qqq123123'):
    driver.delete_all_cookies()
    '''通过request 登陆系统,获取cookie'''
    driver.get(bbs_url)
    driver.find_element_by_xpath('//*[@id="xiding"]/ul/li[1]/a').click()
    driver.find_element_by_xpath('/html/body/div[22]/div[2]/div[2]/ul/li[1]/input').send_keys(account)
    driver.find_element_by_xpath('/html/body/div[22]/div[2]/div[2]/ul/li[2]/input').send_keys(password)
    driver.find_element_by_xpath('/html/body/div[22]/div[2]/div[2]/ul/li[4]/input').click()
    driver.refresh()
    cookies = driver.get_cookies()
    time.sleep(5)
    print(cookies)
    # for cookie_one in cookies:
    #     print(cookie_one)
cookie_login(bbs_url)

 

posted @ 2018-04-27 20:19  Leq123  阅读(4022)  评论(0编辑  收藏  举报