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/
posted on 2021-11-28 23:26 Honey_Badger 阅读(151) 评论(0) 编辑 收藏 举报