URL统一资源定位符:定位资源的,定义互联网上的某一个资源
DNS域名解析
协议://ip地址:端口/项目名/资源URL下载网络资源
我相近办法爬取,B站URL地址,太难了,都是分节传输,我根本找不到啊啊啊
package URL;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class URLDown {
public static void main(String[] args) throws Exception{
//1.下载地址,这里需要一个URL地址,你可以从网络上找一个
URL url = new URL("http://localhost:8080/helloword/index.jsp?username=kuangshen&password=123");
//2.连接到这个资源HTTP
HttpURLConnection urlConnection=(HttpURLConnection) url.openConnection();
//3.读写数据
InputStream inputStream = urlConnection.getInputStream();
FileOutputStream fos = new FileOutputStream("爬取的资源");
byte[] buffer=new byte[1024];
int len;
while ((len=inputStream.read(buffer))!=-1){
fos.write(buffer,0,len);
}
//4.释放资源,断开连接
fos.close();
inputStream.close();
urlConnection.disconnect();
}
}



