• sina博文图片批量下载和博文批量删除


    sina博文图片批量下载

    import cn.hutool.core.io.FileUtil;
    import cn.hutool.http.HttpRequest;
    import cn.hutool.http.HttpUtil;
    import org.jsoup.Jsoup;
    import org.jsoup.nodes.Document;
    import org.jsoup.select.Elements;
    
    import java.io.IOException;
    
    public class DownloadSinaBlogs {
        public static void main(String[] args) throws IOException {
            String url = "网址";
            Document document = Jsoup.connect(url).get();
            Elements elements = document.getElementsByClass("articalContent   ").select("a");
            elements.forEach(e -> {
                String href = e.attr("href");
                href = href.replaceFirst("http://", "https://");
                href = href + ".jpg";
    //            System.out.println(href);
                down(href);
            });
    
        }
    
        private static void down(String url) {
            String dir = "C:\\Users\\Admin\\Pictures\\history\\d\\";  //保存地址
    
            String header = "Connection: keep-alive\n" +
                    "Cache-Control: max-age=0\n" +
                    "Upgrade-Insecure-Requests: 1\n" +
                    "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4734.0 Safari/537.36\n" +
                    "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\n" +
                    "Referer: http://blog.sina.com.cn/\n" +
                    "Accept-Encoding: gzip, deflate\n" +
                    "Accept-Language: zh-HK,zh;q=0.9,en-US;q=0.8,en;q=0.7,zh-CN;q=0.6\n" +
                    "Referrer-Policy: strict-origin-when-cross-origin";
    
            HttpRequest request = HttpUtil.createGet(url, true).header("Referrer-Policy", "strict-origin-when-cross-origin")
                    .header("Upgrade-Insecure-Requests", "1")
                    .header("Referer", "http://blog.sina.com.cn/");
            byte[] bytes = request.execute().bodyBytes();
    
            if (bytes.length > 10) {
                FileUtil.writeBytes(bytes, dir + System.currentTimeMillis() + ".jpg");
            } else {
                System.out.println(bytes.length + "失败:" + url);
            }
    
        }
    
    
    }

    博文批量删除

    as = []
    
    document.body.addEventListener('click', e =>
      ['a', 'cite'].includes(e.target.localName)
      && as.push(e.target.closest('a').getAttribute('href'))
      && console.log('选择了', as[as.length - 1])
    )
    
    new MutationObserver(([m]) => m.removedNodes[0]
      && (
        m.removedNodes[0].nextElementSibling
         .querySelector('cite[id$=OK i]').click(),
        console.log('已删除', as.shift())
      )
    ).observe(document.body, { childList: true, subtree: true })
    
    $$('a[id*=del]').forEach(a => a.click())
    --------------------------------------------------------------------------------------------------------------------------------------------

    作者:Honey_Badger —— 觉得这文章好,点一下左下角

    出处:http://tk55.cnblogs.com/

  • 相关阅读:
    Hive优化
    RDD
    从Hadoop MapReduce到Spark
    Spark on yarn模式
    Hive的web端配置——HWI
    Spark环境搭建
    java身份证号校验
    java手机号码、电子邮箱校验
    服务器运维的日常维护工作
    JavaSSM框架简介
  • 原文地址:https://www.cnblogs.com/tk55/p/15617205.html
Copyright © 2020-2023  润新知