|
|
禁止求评分、诱导评分、互刷评分、互刷悬赏值,违规者封号处理。
禁止发布推广、邀请码、邀请链接、二维码或者有利益相关的任何推广行为。
所有非原创软件请发布在【精品软件区】,发帖必须按照本版块版规格式发帖。
- import org.jsoup.Connection;
- import org.jsoup.Jsoup;
- import org.jsoup.nodes.Document;
- import org.jsoup.nodes.Element;
- import org.jsoup.select.Elements;
-
- import com.gargoylesoftware.htmlunit.WebClient;
- import com.gargoylesoftware.htmlunit.html.HtmlPage;
-
- import java.io.*;
- import java.net.URL;
-
- public class pc {
-
- public static void main(String[] args) throws IOException {
- // TODO Auto-generated method stub
- long t1=System.currentTimeMillis();
- //访问目标网址
- Connection connection1=Jsoup.connect("https://desk.3gbizhi.com/");
- //连接成功后获取Document对象
- Document document1= connection1.get();
- Element elementDiv=document1.selectFirst("[class=menuw mtm]");
- Element elementDiv1=elementDiv.selectFirst("[class=cl r]");//搜索class=cl r 标签
- Element elementUL=elementDiv1.selectFirst("[class=cl]");
- Elements elementLis=elementUL.select("li");//通过找到的ul 搜索ul里面的所有li标签
- for(Element elementLi:elementLis) {//遍历所有找到的li
- Element elementA=elementLi.selectFirst("a");//搜索li里的a标签
- String herURL=elementA.attr("href");//把a标签中的 href属性的值获取到
- //System.out.println(herURL);
- Element elementADiv=elementA.selectFirst("div");//把a标签里的标签找到
- String innerName= elementADiv.text();//把标签里的文字获取到
-
-
-
- System.out.println("创建"+innerName+"文件夹");
- File file=new File("E://桌面//img//"+innerName);
- if(!file.exists()){//如果文件夹不存在
- file.mkdir();//创建文件夹
- }
-
- Connection connection2=Jsoup.connect(herURL);//访问新的小图连接
- Document document2=connection2.get();//
- Element elementDiv2=document2.selectFirst("[class=contlistw mtw]");
- Element elementUl=elementDiv2.selectFirst("[class=cl]");
- Elements elementLI=elementUl.select("li");//搜索ul里的li标签
- for(Element elementLIS:elementLI) {
- Element elementDivName=elementLIS.selectFirst("[class=tips]");
- String divName= elementDivName.text();
- System.out.println("下载"+divName);
-
- Element elementAA=elementLIS.selectFirst("a");//搜索li里的a标签
- String herURLA=elementAA.attr("href");//把a标签中的 href属性的值获取到
- //System.out.println(herURLA);
-
- Connection connection3=Jsoup.connect(herURLA);//访问图片下载的连接 showcontw mtw
- Document document3=connection3.get();
- Element elementDiv3=document3.selectFirst("[class=showcontw mtw]");
-
- Element elementAa=elementDiv3.selectFirst("[class=bz_size_show]");//搜索li里的a标签
- String xiaURL=elementAa.attr("href");
- //System.out.println(xiaURL);
-
-
- URL url=new URL(xiaURL);
- InputStream is=url.openStream();
- FileOutputStream fos=new FileOutputStream("E://桌面//img//"+innerName+"//"+divName+".jpg");
- byte[] b=new byte[2048];
- int count=is.read(b);
- while(count!=-1) {
- fos.write(b,0,count);
- fos.flush();
- count=is.read(b);
- }
- fos.close();
- is.close();
- }
- }
-
- long t2=System.currentTimeMillis();
- double a=(t2-t1)/1000;
- System.out.println("下载完毕"+"用时:"+a+"s");
- }
- }
复制代码
|
|