|
发表于 2016-11-22 22:51:19
|
显示全部楼层
本楼为最佳答案
回帖奖励 +2 鱼币
 - import requests
- import os
- import sqlite3
- import win32crypt
- def get_chrome_cookies(url):
- os.system('copy "C:\\Users\\Administrator\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Cookies" D:\\python-chrome-cookies')#复制谷歌浏览器存储Cookie路径到D盘
- #处理Cookice
- Cookice = sqlite3.connect("d:\\python-chrome-cookies")
- ret_list = []
- ret_dict = {}
- for row in Cookice.execute("select host_key, name, path, value, encrypted_value from cookies"):
- if row[0] != url:
- continue
- ret = win32crypt.CryptUnprotectData(row[4], None, None, None, 0)
- ret_list.append((row[1], ret[1]))
- ret_dict[row[1]] = ret[1].decode()
- Cookice.close()
- os.system('del"D:\\python-chrome-cookies"')#删掉Cookice
- return ret_dict
- #模拟头部
- headers = {
- 'user-agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36',
- }
- #打开链接
- x = requests.get("http://www.douban.com", cookies = get_chrome_cookies(".douban.com"),headers=headers)
- print(x.text)
- if "用户名" in x.text :
- print("登录成功")
- else:
- print("登录失败")
复制代码
|
|