2013年9月16日 星期一

[Java]Jsoup test source code

請搭配Jsoup--好用的抓去網頁工具(HTML & XML)一起觀看
下面附上我的原始碼

package URLConnection;


import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

public class test {
 
 public static void getpoint(String urlStr){ 
    
  Document doc = null;
  try {
   doc = Jsoup.connect(urlStr).get();
  } catch (IOException e1) {
   // TODO Auto-generated catch block
   e1.printStackTrace();
  }
  Elements newsHeadlines1 = doc.select("start_location");
  
  System.out.println(newsHeadlines1.size()); // know the tag size
  System.out.println(newsHeadlines1.get(0)); 
  System.out.println(newsHeadlines1.get(0).text()); // get the text
  System.out.println(newsHeadlines1.get(0).tagName()); // print tag name
  System.out.println(newsHeadlines1.get(0).empty()); // empty the text
 }
 
 public static void main(String[] args){
   
  float start_lat = (float) 24.79608;
  float start_lng = (float) 120.98709;
  float end_lat = (float) 24.80237;
  float end_lng = (float) 120.97206;
  link(start_lat,start_lng,end_lat,end_lng);
  
  
 } 
 public static void link(float start_lat,float start_lng,float end_lat,float end_lng)
 {
  System.out.println("http://maps.googleapis.com/maps/api/directions/xml?origin="+start_lat+","+start_lng+"&destination="+end_lat+","+end_lng+"&sensor=false&units=metric&mode=driving");
     getpoint("http://maps.googleapis.com/maps/api/directions/xml?origin="+start_lat+","+start_lng+"&destination="+end_lat+","+end_lng+"&sensor=false&units=metric&mode=driving");
 }
}

Related Articles

0 意見:

張貼留言

技術提供:Blogger.