Python3 清空CSDN博客

Python3 清空CSDN博客

工作以来一直在CSDN上写博客,最近想把博客整理一遍,重新上传。
无奈有大量冗余博客,所以写个脚本,批量删除博客。

删除一条博客,抓取url请求

Request URL:http://write.blog.csdn.net/postlist?t=del&id=63694679
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding:gzip, deflate
Accept-Language:ja,en;q=0.9
Cookie:'cookie内容'
Host:write.blog.csdn.net
Proxy-Connection:keep-alive
Referer:http://write.blog.csdn.net/postlist?t=del&id=63694679

收集博客的id,放到localStorage

打开http://write.blog.csdn.net/postlist,通过js获取id的集合。

var arr = new Array(localStorage.getItem("arr"))
for (var i=0;i<$(".tdleft").find("a").length;i++){
    var url=$(".tdleft").find("a").eq(i).attr("href");
    arr.push(url.split("/")[6])
}
localStorage.setItem("arr",arr)

使用python删除博客

def sendRequest(url):
import urllib3
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
http = urllib3.PoolManager()
# 设置headers
headers = {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
    "Accept-Encoding": "gzip, deflate",
    "Accept-Language": "ja,en;q=0.9",
    "Host": "write.blog.csdn.net",
    "Referer": "http://write.blog.csdn.net/postlist",
    "Cookie": "cookie",
}

r = http.request(
    'GET', url,
    body=body_data.encode('utf-8'),  # 关键:数据要传入 body 参数,不是 fields
    headers=headers)
print(r.data.decode())

url='http://write.blog.csdn.net/postlist?t=del&id='
sendRequest(url+'博客的id')

哈哈,博客清空了。

来源张永光的博客

你可能感兴趣的:(Python3 清空CSDN博客)