Delete Sina Weibo in bulk using Java code

Source: Internet
Author: User

First scold, Sina Weibo @#@! , without my consent on the forwarding of a variety of micro-blog, manufacturing garbage, but also do not provide micro-BO bulk deletion function, the rogue behavior, shameful hateful, people spit!

Sslclient.java

ImportOrg.apache.http.conn.ClientConnectionManager;ImportOrg.apache.http.conn.scheme.Scheme;ImportOrg.apache.http.conn.scheme.SchemeRegistry;Importorg.apache.http.conn.ssl.SSLSocketFactory;Importorg.apache.http.impl.client.DefaultHttpClient;ImportJavax.net.ssl.SSLContext;ImportJavax.net.ssl.TrustManager;ImportJavax.net.ssl.X509TrustManager;Importjava.security.cert.CertificateException;Importjava.security.cert.X509Certificate; Public classSslclientextendsdefaulthttpclient { PublicSslclient ()throwsException {Super(); Sslcontext CTX= Sslcontext.getinstance ("TLS"); X509trustmanager TM=NewX509trustmanager () {@Override Public voidCheckclienttrusted (x509certificate[] x509certificates, String s)throwscertificateexception {} @Override Public voidCheckservertrusted (x509certificate[] x509certificates, String s)throwscertificateexception {} @Override Publicx509certificate[] Getacceptedissuers () {return NULL;        }        }; Ctx.init (NULL,NewTRUSTMANAGER[]{TM},NULL); Sslsocketfactory SSF=Newsslsocketfactory (CTX, sslsocketfactory.allow_all_hostname_verifier); Clientconnectionmanager CCM= This. Getconnectionmanager (); Schemeregistry SR=Ccm.getschemeregistry (); Sr.register (NewScheme ("https", 443, SSF)); }}

Weibotest.java

ImportOrg.apache.http.HttpResponse;ImportOrg.apache.http.NameValuePair;Importorg.apache.http.client.HttpClient;Importorg.apache.http.client.entity.UrlEncodedFormEntity;ImportOrg.apache.http.client.methods.HttpPost;ImportOrg.apache.http.message.BasicNameValuePair;ImportOrg.jsoup.Jsoup;Importorg.jsoup.nodes.Document;Importorg.jsoup.nodes.Element;Importorg.jsoup.select.Elements;ImportJava.io.BufferedReader;ImportJava.io.File;ImportJava.io.FileReader;Importjava.util.ArrayList;ImportJava.util.HashMap;ImportJava.util.Iterator;Importjava.util.List;ImportJava.util.Map; Public classWeibotest { Public Static FinalString url = "Https://weibo.com/aj/mblog/del?ajwvr=6";  Public Static FinalString charset = "Utf-8";  Public Static voidMain (string[] args)throwsException {/*** Sina_weibo.txt from Weibo page F12 get format is * <div node-type= "feed_list" > * <div action-type= " Feed_list_item "></div> * <div action-type=" Feed_list_item "></div> * <div A     Ction-type= "Feed_list_item" ></div> * <div action-type= "Feed_list_item" ></div> * <div action-type= "Feed_list_item" ></div> * ... * </div>*/File File=NewFile ("C:\\users\\nihaorz\\desktop\\sina_weibo.txt"); BufferedReader BR=NewBufferedReader (Newfilereader (file)); StringBuffer SB=NewStringBuffer ();        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=Newhttppost (URL);        AddHeader (HttpPost);  while(It.hasnext ()) {element element=It.next (); String Mid= Element.attr ("Mid");            System.out.println (mid);        Execute (httppost, mid); }    }    Private Static voidExecute (HttpPost httppost, String mid)throwsException {HttpClient HttpClient=Newsslclient (); //Setting Parameterslist<namevaluepair> list =NewArraylist<namevaluepair>(); Map<string, string> map =NewHashmap<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 (NewBasicnamevaluepair (Elem.getkey (), Elem.getvalue ())); }        if(List.size () > 0) {urlencodedformentity entity=Newurlencodedformentity (list, CharSet);        Httppost.setentity (entity); } HttpResponse resp=Httpclient.execute (HttpPost);    System.out.println (RESP); }    Private Static voidAddHeader (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"); /*** Set your own 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"); }}

Delete Sina Weibo in bulk using Java code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.