python3批量删除豆瓣分组下的好友的实现代码
作者:jingxian 时间:2022-02-14 22:27:13
python3批量删除豆瓣分组下的好友的实现代码
"""
python3批量删除豆瓣分组下的好友
2016年6月7日 03:43:42 codegay
我两年前一时冲动在豆瓣关注了很多豆瓣的员工,好多,有四百个。
我现在一时冲动想取消关注...,写这么一个脚本可以用来加快删除的速度。
cookies还是直接从chrome读取出来用,
参考我之前刚写的代码 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
#运行环境windows 2012 server python3.4 x64 pywin32 chrome 50
#getcookiefromchrome()
#getcookiefromchrome('.baidu.com')
dbcookies=getcookiefromchrome('.douban.com')
txt=requests.get('https://www.douban.com/contacts/list?tag=1718',cookies=dbcookies).text
#print(txt)
userid=re.findall(r'id="u(\d+)"',txt)
ck=dbcookies['ck']
#ck的值在每次重新登录豆版后会变化。
#可以从网页中提取,不过我发现cookies也记录有了。直接提取出来就好了
head={'Content-Type':'application/x-www-form-urlencoded',}
for uid in userid:
data="people=%s&ck=%s" % (uid,ck)
#data='people=47362624&ck=jeGZ'
print(data)
rs=requests.post('https://www.douban.com/j/contact/removecontact',headers=head,cookies=dbcookies,data=data).text
print(rs)
标签:python3,批量,删除,分组
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
PHP使用自定义key实现对数据加密解密的方法
2023-08-21 12:48:37
jQuery.data()方法与内存泄漏
2010-04-06 17:20:00
![](https://img.aspxhome.com/file/UploadPic/20104/6/01-17s.jpg)
AI:如何训练机器学习的模型
2023-01-16 13:18:49
![](https://img.aspxhome.com/file/2023/8/81698_0s.png)
详解OpenCV-Python Bindings如何生成
2021-03-26 17:33:52
爱你就要说出来,来表白吧
2008-11-23 16:23:00
![](https://img.aspxhome.com/file/UploadPic/200811/23/loveyou-38s.gif)
Python requests HTTP验证登录实现流程
2021-02-27 16:43:04
![](https://img.aspxhome.com/file/2023/7/75337_0s.png)
python 异常捕获详解流程
2022-06-12 15:31:04
![](https://img.aspxhome.com/file/2023/9/71519_0s.jpg)
公用样式模板的设计制作
2009-09-13 21:27:00
![](https://img.aspxhome.com/file/UploadPic/20099/13/sys1-12s.jpg)
perl批量查询ip归属地的方法代码
2023-08-11 22:53:54
基于python实现垂直爬虫系统的方法详解
2023-11-17 13:33:38
FckEditor配置手册中文教程详细说明
2010-02-28 12:37:00
sqlserver 临时表 Vs 表变量 详细介绍
2011-11-03 17:34:10
简单介绍一下pyinstaller打包以及安全性的实现
2021-07-23 15:34:56
![](https://img.aspxhome.com/file/2023/8/78718_0s.png)
利用python实现可视化大屏
2023-08-17 17:29:17
![](https://img.aspxhome.com/file/2023/9/65489_0s.png)
JS 中触发 A 标签的点击事件
2009-01-11 17:30:00
如何利用python读取图片属性信息
2023-12-24 00:57:51
![](https://img.aspxhome.com/file/2023/3/64353_0s.png)
MYSQL server has gone away解决办法
2010-11-25 17:22:00
flask开启多线程的具体方法
2023-03-10 06:30:50
Python数据分析之双色球基于线性回归算法预测下期中奖结果示例
2021-12-04 12:39:55
![](https://img.aspxhome.com/file/2023/8/69578_0s.jpg)
jquery 使用点滴函数代码
2011-05-21 16:12:00