首先开骂,新浪微博@#@!,不经我同意就转发各种微博,制造垃圾,还不提供微博批量删除功能,摆明了的流氓行为,可耻可恨,遭人唾弃!

SSLClient.java

import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient; import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate; public class SSLClient extends DefaultHttpClient { public SSLClient() throws Exception {
super();
SSLContext ctx = SSLContext.getInstance("TLS");
X509TrustManager tm = new X509TrustManager() { @Override
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { } @Override
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { } @Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
ctx.init(null, new TrustManager[]{tm}, null);
SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
ClientConnectionManager ccm = this.getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", 443, ssf));
}
}

WeiboTest.java

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.message.BasicNameValuePair;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements; import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map; public class WeiboTest { public static final String url = "https://weibo.com/aj/mblog/del?ajwvr=6";
public static final String charset = "utf-8"; public static void main(String[] args) throws Exception {
/**
* sina_weibo.txt由微博页面F12获得格式是
* <div node-type="feed_list">
* <div action-type="feed_list_item"></div>
* <div action-type="feed_list_item"></div>
* <div action-type="feed_list_item"></div>
* <div action-type="feed_list_item"></div>
* <div action-type="feed_list_item"></div>
* ...
* </div>
*/
File file = new File("C:\\Users\\Nihaorz\\Desktop\\sina_weibo.txt");
BufferedReader br = new BufferedReader(new FileReader(file));
StringBuffer sb = new StringBuffer();
String str;
while ((str = br.readLine()) != null) {
sb.append(str).append("\n");
}
System.out.println(sb);
br.close(); Document doc = Jsoup.parseBodyFragment(sb.toString());
Element body = doc.body();
Elements elements = body.select("div[action-type='feed_list_item']");
Iterator<Element> it = elements.iterator();
HttpPost httpPost = new HttpPost(url);
addHeader(httpPost);
while (it.hasNext()) {
Element element = it.next();
String mid = element.attr("mid");
System.out.println(mid);
execute(httpPost, mid);
}
} private static void execute(HttpPost httpPost, String mid) throws Exception {
HttpClient httpClient = new SSLClient();
//设置参数
List<NameValuePair> list = new ArrayList<NameValuePair>();
Map<String, String> map = new HashMap<String, String>();
map.put("mid", mid);
Iterator<Map.Entry<String, String>> iterator = map.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, String> elem = iterator.next();
list.add(new BasicNameValuePair(elem.getKey(), elem.getValue()));
}
if (list.size() > 0) {
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, charset);
httpPost.setEntity(entity);
}
HttpResponse resp = httpClient.execute(httpPost);
System.out.println(resp);
} private static void addHeader(HttpPost httpPost) {
httpPost.addHeader("Accept", "*/*");
httpPost.addHeader("Accept-Encoding", "gzip, deflate, br");
httpPost.addHeader("Accept-Language", "zh-CN,zh;q=0.9");
httpPost.addHeader("Connection", "keep-alive");
httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded");
/**
* 设置自己的cookie
*/
httpPost.addHeader("Cookie", "***");
httpPost.addHeader("Host", "weibo.com");
httpPost.addHeader("Origin", "https://weibo.com");
httpPost.addHeader("Referer", "https://weibo.com/1864722372/profile?rank=1&is_all=1");
httpPost.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36");
httpPost.addHeader("X-Requested-With", "XMLHttpRequest");
} }

使用java代码批量删除新浪微博的更多相关文章

  1. 【Oracle/Java】批量删除16张十万数据的表 单线程耗时45秒 多线程耗时38秒

    昨天做了插入的单线程多线程比较,今天做个删除的. 单线程批量删除类代码: package com.hy.delete.singlethread; import java.sql.Connection; ...

  2. Java 代码完成删除文件、文件夹操作

    import java.io.File;/** * 删除文件和目录 * */public class DeleteFileUtil {    /**     * 删除文件,可以是文件或文件夹     ...

  3. Java代码批量插入数据到MySQL

    1.批量插入 import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundExc ...

  4. Redis批量删除缓存数据

    背景: 在使用redis中,经常会遇到批量删除缓存的情况,但是对于在客户端中,如果一个一个的删除key,则需要较长时间及相对麻烦,可以使用以下命令,批量删除缓存. 本地批量删除KEY: ./redis ...

  5. tp5 全选,全不选 ,ajax批量删除

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. springmvc+mybatis用多选框批量删除的功能Java代码

    今天写了一个批量删除的功能,在后台传值过程中一直出错,最终还是请教了北京的一位高手帮我解决的,在此首先要好好感谢他,以后我有幸能帮助别人的话,决不推辞. 废话不说,直接进入正题,我会将在编写过程中出现 ...

  7. mySql事务_ _Java中怎样实现批量删除操作(Java对数据库进行事务处理)?

      本文是记录Java中实现批量删除操作(Java对数据库进行事务处理),在开始之前先来看下面这样的一个页面图: 上面这张图片显示的是从数据库中查询出的出租信息,信息中进行了分页处理,然后每行的前面提 ...

  8. Magicodes.WeiChat——ASP.NET Scaffolding生成增删改查、分页、搜索、删除确认、批量操作、批量删除等业务代码

    关于T4代码生成这块,我之前写过几篇帖子,如:<Magicodes.NET框架之路——让代码再飞一会(ASP.NET Scaffolding)>(http://www.cnblogs.co ...

  9. SQL中批量删除被注入的恶意代码的方法

    下文将为您介绍SQL中批量删除被注入的恶意代码的方法,供您参考,如果您也遇到了这样的问题,不妨一看,相信对您会有所帮助. 1,如果你的数据表很少的话,那么写几条简单的sql就搞定了 对于表中的nvch ...

随机推荐

  1. JVM参数配置 java内存区域

    java内存区域 一些基本概念 http://www.importnew.com/18694.html https://www.cnblogs.com/wangyayun/p/6557851.html ...

  2. 编剧小记 — Contour

    前言 Contour 是一款比较优秀的编剧辅助软件,按理说这篇文章应该归类到mac小记中,但其操作非常简单,基本上以写作提示为主.只怪所有提示都是英语,而且很多,每次使用打开 Contour 个别单词 ...

  3. Jmeter(三十八)while控制器实现ssh三次重连

    在jmeter中,可以使用SSH协议连接主机进行相关操作, 步骤如下 首先添加一个ssh command  我们的测试交流群:317765580 在command中填写远程连接的必要信息 结果树中可以 ...

  4. Filebeat简介

    原文地址:http://blog.51cto.com/seekerwolf/2110174 收集日志的目的是有效的利用日志,有效利用日志的前提是日志经过格式化符合我们的要求,这样才能真正的高效利用收集 ...

  5. H5 13-子元素选择器

    13-子元素选择器 p{ color: red; } */ /* #identity>p{ color: blue; } */ div>ul>li>p{ color: purp ...

  6. bug总结

    1.被除数为0 2.Java 空指针异常(java.lang.NullPointerException) 即对象没有进行实例化便进行了使用.实例化的意义,就是将对象实例的地址赋值给对象符号. 比如 S ...

  7. (FZU 2150) Fire Game (bfs)

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=2150 Problem Description Fat brother and Maze are playing ...

  8. Navicat还原出现Finished - Stopped before completion的问题

    查看数据库中最大的单个文件容量 SHOW VARIABLES LIKE '%max_allowed_packet%';   设置最大单个文件容量为10M,单次有效(新建查询---运行) SET GLO ...

  9. 分析一个react项目

    目录结构 下面是使用npx create-react-app web-app来创建的一个项目(已经删除了多余的文件) web-app ├── node_modules │   ├── ....... ...

  10. 【学习总结】GirlsInAI ML-diary day-5-布尔表达式/Bool

    [学习总结]GirlsInAI ML-diary 总 原博github链接-day5 认识布尔表达式 简单来说,bool 就是对错判断. 给个条件,如果满足条件就返回True, 不满足条件就返回Fal ...