<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ### 第1關 : 利用Jsoup抓取攜程旅游網的數據 ``` public Document getHtml1(String url) throws IOException{ Document document = Jsoup.parse( new File( "./backups/www.ctrip.com.txt" ) , "utf-8" ); // System.out.println(document.title()); // System.out.println(document); return document; } /** * * @param url 網址http://hotels.ctrip.com/domestic-city-hotel.html * @return * @throws IOException */ public Document getHtml2(String url) throws IOException{ Document document = Jsoup.parse( new File( "./backups/hotels.ctrip.com_domestic-city-hotel.txt" ) , "utf-8" ); //System.out.println(document.title()); return document; } } ``` ### 第2關:解析并提取HTML 元素(一) ``` public Document getDoc1(String url) throws IOException{ File file=new File("./backups/www.ctrip.com.txt"); Document document =Jsoup.parse(file,"UTF-8","http://www.ctrip.com/"); return document ; } //獲取“http://you.ctrip.com/”的Docment對象 public Document getDoc2(String url) throws IOException{ File file=new File("./backups/you.ctrip.com.txt"); Document document =Jsoup.parse(file,"UTF-8","http://you.ctrip.com"); return document ; } //獲取所有鏈接 public Elements getLinks(Document doc){ Elements links=doc.select("link[href]"); return links; } //獲取第一個class為“pop_attention”的div public Element getDiv(Document doc){ Element element =doc.select("div.pop_attention").first(); return element ; } //獲取所有li之后的i標簽 public Elements getI(Document doc){ Elements element =doc.select("li>i"); return element ; } ``` ### 第3關:解析并提取HTML 元素(二) ``` //獲取“http://hotels.ctrip.com/”Docment對象 public Document getDoc1(String url) throws IOException{ File file=new File("./backups/hotel.ctrip.com.txt"); Document doc=Jsoup.parse(file,"UTF-8","http://hotels.ctrip.com/"); return doc; } //獲取“http://hotels.ctrip.com/domestic-city-hotel.html”的Docment對象 public Document getDoc2(String url) throws IOException{ File file1=new File("./backups/hotels.ctrip.com_domestic-city-hotel.txt"); Document doc=Jsoup.parse(file1,"UTF-8","http://hotels.ctrip.com/domestic-city-hotel.html"); return doc; } //獲取所有鏈接 public List<String> getLinks(Document doc){ List<String> ar=new ArrayList<>(); Elements kk=doc.select("a[href]"); for(Element gg:kk){ ar.add(gg.tagName()+"$"+gg.attr("abs:href")+"("+gg.text()+")"); } return ar; } //獲取圖片 public List<String> getMedia(Document doc){ List<String> list=new ArrayList<>(); Elements ll=doc.select("[src]"); for(Element h:ll){ if(h.tagName().equals("img")){ list.add(h.tagName()+"$"+h.attr("abs:src")); } } return list; } //獲取link[href]鏈接 public List<String> getImports(Document doc){ List<String> list=new ArrayList<>(); Elements kk=doc.select("link[href]"); for(Element g:kk){ list.add(g.tagName()+"$"+g.attr("abs:href")+"("+g.attr("rel")+")"); } return list; } } ``` #### 第4關:使用Jsoup抓取攜程旅游網全國城市信息 ``` public Document getDoc(String url) throws IOException{ File file=new File("backups/hotels.ctrip.com_domestic-city-hotel.txt"); Document doc=Jsoup.parse(file,"UTF-8","http://hotels.ctrip.com/"); return doc; } /** * 獲取所有城市返回城市信息集合 * @param doc * @return */ public List<HotelCity> getAllCitys(Document doc){ List<HotelCity> cities = new ArrayList<HotelCity>(); Elements aa= doc.getElementsByClass("pinyin_filter_detail layoutfix"); Element pp = aa.first(); Elements hh= pp.getElementsByTag("dd"); Elements hts=pp.getElementsByTag("dt"); for (int i = 0; i < hh.size(); i++) { Element bb = hts.get(i); Element head_hotelsLink = hh.get(i); Elements links = head_hotelsLink.children(); for (Element link : links) { String pinyin_cityId = link.attr("href").replace("/hotel/", ""); String pinyin = pinyin_cityId.replace(StringUtil.getNumbers(link.attr("href")), "");//截取拼音 HotelCity city = new HotelCity(); city.setCityId(StringUtil.getNumbers(link.attr("href"))); //截取cityId city.setCityName(link.text()); city.setHeadPinyin(bb.text()); city.setPinyin(pinyin); cities.add(city); } } return cities; } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看