python3批量删除豆瓣分组下的好友 | """ | | python3批量删除豆瓣分组下的好友 | | 2016年6月7日 03:43:42 codegay | | | | 我两年前一时冲动在豆瓣关注了很多豆瓣的员工,好多,有四百个。 | | 我现在一时冲动想取消关注...,写这么一个脚本可以用来加快删除的速度。 | | | | cookies还是直接从chrome读取出来e, | | 参考我之前刚写的代码 python3从chrome浏览器读取cookie, | | | | """ | | | | import os | | import sqlite3 | | import re | | import requests | | from win32.win32crypt import CryptUnprotectData | | | | def getcookiefromchrome(host='.oschina.net'): | | cookiepath=os.environ['LOCALAPPDATA']+r"\Google\Chrome\User Data\Default\Cookies" | | sql="select host_key,name,encrypted_value from cookies where host_key='%s'" % host | | with sqlite3.connect(cookiepath) as conn: | | cu=conn.cursor() | | cookies={name:CryptUnprotectData(encrypted_value)[1].decode() for host_key,name,encrypted_value in cu.execute(sql).fetchall()} | | print(cookies) | | return cookies | | | | | | | | | | dbcookies=getcookiefromchrome('.douban.com') | | | | txt=requests.get('https://www.douban.com/contacts/list?tag=1718',cookies=dbcookies).text | | | | userid=re.findall(r'id="u(\d+)"',txt) | | | | ck=dbcookies['ck'] | | | | | | | | head={'Content-Type':'application/x-www-form-urlencoded',} | | | | for uid in userid: | | data="people=%s&ck=%s" % (uid,ck) | | | | print(data) | | rs=requests.post('https://www.douban.com/j/contact/removecontact',headers=head,cookies=dbcookies,data=data).text | | print(rs)COPY |
|