美文网首页
Python3 清空CSDN博客

Python3 清空CSDN博客

作者: 张永光 | 来源:发表于2018-01-16 14:07 被阅读0次

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博客

    Python3 清空CSDN博客 工作以来一直在CSDN上写博客,最近想把博客整理一遍,重新上传。无奈有大量冗余博...

  • CSDN博客

    我的CSDN博客地址: http://blog.csdn.net/zixiweimi, 不定时转载一些ios实用文章

  • CSDN 博客

    更喜欢 CSDN 的博客,GO GO GO!http://blog.csdn.net/xiewen99/

  • CSDN博客

    我的CSDN博客地址:http://blog.csdn.net/jiaobuchong,欢迎大家访问拍砖。

  • 将博客搬至CSDN

    将博客搬至CSDN将博客搬至CSDN将博客搬至CSDN将博客搬至CSDN将博客搬至CSDN将博客搬至CSDN将博客...

  • 将博客搬至CSDN

    将博客搬至CSDN将博客搬至CSDN将博客搬至CSDN将博客搬至CSDN将博客搬至CSDN将博客搬至CSDN将博客...

  • 将博客搬至CSDN

    将博客搬至CSDN将博客搬至CSDN将博客搬至CSDN将博客搬至CSDN将博客搬至CSDN将博客搬至CSDN

  • 将博客搬至CSDN

    将博客搬至vvCSDN将博客搬至CSDN将博客搬至CSDN将博客搬至CSDN将博客搬至CSDN将博客搬至CSDN将...

  • CSDN博客搬家

    之前一直使用CSDN写博客,但是最近发现编辑的时候总是出现闪退,重新打开也无法再编辑,很是头疼; --- 原博客地...

  • 开通CSDN博客

    我在CSDN开通了个人微博,欢迎前来围观http://blog.csdn.net/maxwell315

网友评论

      本文标题:Python3 清空CSDN博客

      本文链接:https://www.haomeiwen.com/subject/sxusoxtx.html