QQ空间获得g_tk Python
来源:互联网 发布:memcache java 编辑:程序博客网 时间:2024/04/28 16:50
QQ空间获得g_tk Python
对于想要对QQ空间数据进行爬取的童鞋们,一定会遇到不知道怎么获得请求参数g_tk的问题。这其实是个非常!简单!的问题!
g_qzonetoken 获取的方法:http://blog.csdn.net/vision_tung/article/details/78888639
g_tk:
- 获得请求Cookies中的p_skey参数,然后通过加密算法获得一串唯一的字符串
- 腾讯公司为了信息安全所做的安全措施
- 这一字符串在一次登陆过程中不会改变
- 对用户不可见
- 缺少此参数不予接受请求
具体算法:
def getGTK(cookie): hashes = 5381 for letter in cookie['p_skey']: hashes += (hashes << 5) + ord(letter) return hashes & 0x7fffffff
附代码:
driver = webdriver.Chrome(executable_path=r'C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\Scripts\phantomjs-2.1.1-windows\phantomjs-2.1.1-windows\bin\chromedriver.exe') #这个是chormedriver的地址 driver.get('https://qzone.qq.com/') driver.switch_to.frame('login_frame') driver.find_element_by_id('switcher_plogin').click() driver.find_element_by_id('u').clear() driver.find_element_by_id('u').send_keys('1023006144') #这里填写你的QQ号 driver.find_element_by_id('p').clear() driver.find_element_by_id('p').send_keys('199611sxd') #这里填写你的QQ密码 driver.find_element_by_id('login_button').click() time.sleep(2) #---------------获得 gtk cookie = {}#初始化cookie字典 for elem in driver.get_cookies():#取cookies cookie[elem['name']] = elem['value'] gtk=getGTK(cookie)#通过getGTK函数计算gtk
搞定!
注:如有不足,请斧正。微信:cmdegz5sxd
阅读全文