http://maps.google.com/maps/geo?q=%C9%CF%BA%A3&output=xml&key=abcdefg
这个是链接,将它复制到地址栏并访问就可以显示出一个xml页面, <?xml version="1.0" encoding="UTF-8" ?>
- <kml xmlns="http://earth.google.com/kml/2.0">
- <Response>
<name>上海</name>
- <Status>
<code>200</code>
<request>geocode</request>
</Status>
- <Place id="p1">
<address>中华人民共和国上海市</address>
- <AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0">
- <Country>
<CountryNameCode>CN</CountryNameCode>
<CountryName>中国</CountryName>
- <Locality>
<LocalityName>上海市</LocalityName>
</Locality>
</Country>
</AddressDetails>
- <ExtendedData>
<LatLonBox north="31.5291930" south="30.9185268" east="121.9881535" west="120.9636783" />
</ExtendedData>
- <Point>
<coordinates>121.4759159,31.2243531,0</coordinates>
</Point>
</Place>
</Response>
</kml>但是我用java小程序下载它的页面源代码的时候就无法把浏览到的东西全部弄下来,只能弄下来一点<?xml version="1.0" encoding="UTF-8" ?>
<kml xmlns="http://earth.google.com/kml/2.0"><Response>
<name>上海</name>
<Status>
<code>602</code>
<request>geocode</request>
</Status>
</Response></kml>
为什么啊?
下面是我的程序代码,写得有点粗糙。import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;public class openUrl { private static final String gasUrl = "http://maps.google.com/maps/geo?q=上海&output=xml&key=abcdefg";
public static void main(String[] args) throws Exception {
generateFile(gasUrl);
// }
} public static void generateFile(String urlStr) throws Exception {
URL url = new URL(urlStr); URLConnection connection = url.openConnection(); InputStream inputStream = connection.getInputStream(); BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(inputStream)); String line = null;
while ((line = bufferedReader.readLine()) != null) {
System.out.println(line); }
}
}
这个是链接,将它复制到地址栏并访问就可以显示出一个xml页面, <?xml version="1.0" encoding="UTF-8" ?>
- <kml xmlns="http://earth.google.com/kml/2.0">
- <Response>
<name>上海</name>
- <Status>
<code>200</code>
<request>geocode</request>
</Status>
- <Place id="p1">
<address>中华人民共和国上海市</address>
- <AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0">
- <Country>
<CountryNameCode>CN</CountryNameCode>
<CountryName>中国</CountryName>
- <Locality>
<LocalityName>上海市</LocalityName>
</Locality>
</Country>
</AddressDetails>
- <ExtendedData>
<LatLonBox north="31.5291930" south="30.9185268" east="121.9881535" west="120.9636783" />
</ExtendedData>
- <Point>
<coordinates>121.4759159,31.2243531,0</coordinates>
</Point>
</Place>
</Response>
</kml>但是我用java小程序下载它的页面源代码的时候就无法把浏览到的东西全部弄下来,只能弄下来一点<?xml version="1.0" encoding="UTF-8" ?>
<kml xmlns="http://earth.google.com/kml/2.0"><Response>
<name>上海</name>
<Status>
<code>602</code>
<request>geocode</request>
</Status>
</Response></kml>
为什么啊?
下面是我的程序代码,写得有点粗糙。import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;public class openUrl { private static final String gasUrl = "http://maps.google.com/maps/geo?q=上海&output=xml&key=abcdefg";
public static void main(String[] args) throws Exception {
generateFile(gasUrl);
// }
} public static void generateFile(String urlStr) throws Exception {
URL url = new URL(urlStr); URLConnection connection = url.openConnection(); InputStream inputStream = connection.getInputStream(); BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(inputStream)); String line = null;
while ((line = bufferedReader.readLine()) != null) {
System.out.println(line); }
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货