python获取浏览器cookies登录熊猫tv
2017-05-18 22:06
141 查看
在C:\Users\lenovo\AppData\Local\Google\Chrome\User Data\Default路径下查找已经在chrome上登录的cookies,然后用requests访问
获取账号信息
from os import getenv
import sqlite3
import win32crypt
import requests
import Cookiestest
import json
def getPandaCookies():
conn = sqlite3.connect(getenv("LOCALAPPDATA") + "\Google\Chrome\User Data\Default\Cookies")
cursor = conn.cursor()
cursor.execute('select host_key,name,encrypted_value from cookies where host_key like "%panda.tv%"')
cookies=""
for result in cursor.fetchall():
# print result
value = win32crypt.CryptUnprotectData(result[2], None, None, None, 0)[1]
if value:
cookies+="%s=%s; "%(result[1],value)
# print 'host_key: ' + result[0]
# print 'name: ' + result[1]
# print 'Password: ' + value
else:
print "no password found"
cursor.close()
return cookies
Url="http://www.panda.tv/ajax_get_myinfo"
cookies=getPandaCookies()
headers = {"Cookie":cookies,
"Host":"www.panda.tv",
"Accept-Encoding":"gzip, deflate",
"Referer":"http://www.panda.tv/personal",
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:53.0) Gecko/20100101 Firefox/53.0",
"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
}
html=requests.get(Url,headers=headers)
html.encoding="utf-8"
print html.text
data=json.loads(html.text)
print data["data"]["nickName"]
http://www.panda.tv/ajax_get_myinfo
获取账号信息
from os import getenv
import sqlite3
import win32crypt
import requests
import Cookiestest
import json
def getPandaCookies():
conn = sqlite3.connect(getenv("LOCALAPPDATA") + "\Google\Chrome\User Data\Default\Cookies")
cursor = conn.cursor()
cursor.execute('select host_key,name,encrypted_value from cookies where host_key like "%panda.tv%"')
cookies=""
for result in cursor.fetchall():
# print result
value = win32crypt.CryptUnprotectData(result[2], None, None, None, 0)[1]
if value:
cookies+="%s=%s; "%(result[1],value)
# print 'host_key: ' + result[0]
# print 'name: ' + result[1]
# print 'Password: ' + value
else:
print "no password found"
cursor.close()
return cookies
Url="http://www.panda.tv/ajax_get_myinfo"
cookies=getPandaCookies()
headers = {"Cookie":cookies,
"Host":"www.panda.tv",
"Accept-Encoding":"gzip, deflate",
"Referer":"http://www.panda.tv/personal",
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:53.0) Gecko/20100101 Firefox/53.0",
"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
}
html=requests.get(Url,headers=headers)
html.encoding="utf-8"
print html.text
data=json.loads(html.text)
print data["data"]["nickName"]
相关文章推荐
- cas用httpclient登录,并获取ticket,可以很方便扩展,如果要ajax登录可以基于这个接口,在resp种植castgc的cookie到浏览器
- Python脚本简单实现打开默认浏览器登录人人和打开QQ的方法
- python获取cookies
- selenium+python实现1688登录 —— iframe中元素获取
- Python3.X登录模拟CSDN,获取文章列表
- selenium_webdriver(python)获取元素属性值,浏览器窗口控制、网页前进后退,title/url打印
- python模拟登录百度代码分享(获取百度贴吧等级)
- python模拟浏览器打开百度首页并登录或者点击首页新闻并保存网页
- PHP CURL获取cookies模拟登录…
- yii2获取登录前的页面url地址--电脑和微信浏览器上的实现以及yii2相关源码的学习
- Python爬虫实战(5):模拟登录淘宝并获取所有订单(1)
- Python登录并获取CSDN博客所有文章列表
- 通过selenium来模拟登录,获取登录后的cookies
- python+cookielib实现批量利用账号和密码自动获取新浪微博登录cookie
- 获取腾讯企业邮箱通讯录python脚本(带登录功能)
- 如何使用python自动登录路由器且获取页面内容
- Python+selenium 获取浏览器窗口坐标、句柄的方法
- 终极利器!利用appium和mitmproxy登录获取cookies
- 基于webkit浏览器,自动获取完整cookie的方法 -- python