public class GetUrlInfo
{
    public static void printfInfo(URL url)throws Exception
    {
        //基本信息
        System.out.println("文件        "+url.getFile());
        System.out.println("Protocol        "+url.getProtocol());//获取URL的协议名称
        System.out.println("host        "+url.getHost());
        System.out.println("端口        "+url.getPort());//获取URl的端口号
        System.out.println("路径        "+url.getPath());//获取URL的路径部分
 
 
        URLConnection c=url.openConnection();
        c.connect();
        System.out.println("Contend type        "+c.getContentType());
        System.out.println("Contend Encoding        "+c.getContentEncoding());
        System.out.println("Contend Length        "+c.getContentLength());
        System.out.println("Date        "+new Date(c.getDate()));
        System.out.println("Date        "+new Date(c.getLastModified()));
        System.out.println("Expriration        "+new Date(c.getExpiration()));
 
        if(c instanceof HttpURLConnection)
        {
            HttpURLConnection h=(HttpURLConnection) c;
            System.out.println(" reust Method        "+h.getRequestMethod());
            System.out.println(" Resonse Message        "+h.getResponseMessage());
            System.out.println(" Resonse Code         "+h.getResponseCode());
        }
 
 
 
    }
 
    public static void vist(URL url)throws Exception//抓取某网站的内容
    {
 
        File file=new File("C:/hhh2.txt");
        String tempString;
        StringBuffer sb=new StringBuffer();
         //InputStream in=new InputStreamReader(url.openStream())
        BufferedReader in=new BufferedReader(new InputStreamReader(url.openStream()));
        BufferedWriter out=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
        while((tempString=in.readLine())!=null)
        {
            //out.write(tempString);
            //sb.append(tempString);
            System.out.println(tempString);
        }
        in.close();
        out.close();
        System.out.println(sb.toString());
    }
    public static void main(String []args)
    {
        String urlString="https://www.zhihu.com/question/48629658";
        try
        {
            URL url=new URL(urlString);
            System.out.println(url.getUserInfo());
            vist(url);
            //printfInfo(url);
        } catch (Exception e)
        {
            // TODO: handle exception
        }
 
    }
}

获得URl信息的更多相关文章

  1. 一个用php实现的获取URL信息的类

    获取URL信息的类 使用这个类,你能获得URL的如下信息: - Host  - Path  - Statuscode (eg. 404,200, ...)  - HTTP Version  - Ser ...

  2. ASP.NET获取请求的url信息汇总

    ASP.NET获取请求的url信息汇总 最近做项目需要处理一个用代码获取当前网站的域名或ip信息的问题,于是尝试了ASP.NET中各种获取url信息的方法,在此总结一下: 在Global.asax文件 ...

  3. PHP模拟发送POST请求之二、用PHP和JS处理URL信息

    明白了HTTP请求的头信息后,我们还需要对请求地址有所了解.再者,HTTP GET请求是靠URL实现的,所以了解URL的构造,处理URL的重要性不言而喻. 在PHP中我们用parse_url()函数来 ...

  4. jQuery 获取 URL信息

    jQuery获取URL信息有很多方法,但是使用这个插件就非常爽了. 托管地址在:http://github.com/allmarkedup/jQuery-URL-Parser // http: //l ...

  5. NodeJS的url信息截取模块url-extract

    NodeJS的url信息截取模块url-extract2013-09-12 22:49 by Justany_WhiteSnow, 212 阅读, 0 评论, 收藏, 编辑 上一篇文章,介绍了怎么利用 ...

  6. js得到当前页面的url信息方法

    js得到当前页面的url信息方法:http://www.cnblogs.com/zuosong160522/p/5755615.html js获取url传递参数,js获取url?后面的参数:http: ...

  7. VB6获取Chrome地址栏的URL信息

    上篇写到了获取IE8浏览器URL的一般方法,那这篇就写下chrome的URL怎么获取.事实上,早期的chrome版本可以通过跟IE8差不多方式获取到URL信息.但是,现在chrome的控件都是Dire ...

  8. VB6获取IE8的地址栏的URL信息

    这是个老梗了,也没什么技术含量.因为自从接触Linux之后,Windows上我所知道的那一点api基本上都忘光了.所以这样的博文可以当做是备忘,说不定有天还能用的到. Windows上想要获取浏览器的 ...

  9. 获取当前页面的URL信息

    以前在做网站的时候,经常会遇到当前页的分类高亮显示,以便让用户了解当前处于哪个页面.之前一直是在每个不同页面写方法.工程量大,也不便于修改.一直在想有什么简便的方法实现.后来在网上查到可以用获取当前U ...

  10. Javascrip获取页面URL信息

    使用Javascript可以方便获得页面的参数信息,常用的几种如下: 设置或获取对象指定的文件名或路径 window.location.pathname   设置或获取整个 URL 为字符串 wind ...

随机推荐

  1. leetcode problem (2-4)

    Problem 2 --- Add Two Numbers 简单的模拟题. Problem 3 --- Longest Substring Without Repeating Characters 题 ...

  2. Python中dict详解

    from:http://www.cnblogs.com/yangyongzhi/archive/2012/09/17/2688326.html Python中dict详解 python3.0以上,pr ...

  3. .net ajax式上传文件

    今天在这里介绍一下ajax上传文件.其实也不算是真的使用xmlhttprequest上传,只是使用了iframe实现了无刷新上传而已,最多也只算 是仿ajax上传文件.然而网上关于使用xmlhttpr ...

  4. apache .htaccess 伪静态重定向,防盗链 限制下载...

    301全站跳转 RewriteEngine OnRewriteCond %{HTTP_HOST} ^www\.old\.net$ [NC]RewriteRule ^(.*)$ http://www.n ...

  5. HTML 表格的书写方式:

    首先要进行reset  table{border-collapse:collapse;border-spacing:0;}th{text-align:inherit;} 1. caption标签对整个 ...

  6. (转载)在Delphi中利用MSDASC来配置数据库链接

    在Delphi中利用MSDASC来配置数据库链接 在运行期进行数据库的连接是一个问题,自己写一个窗体配置吧,数据库不一样,所用的参数也不一样,还有那讨厌的连接字符串,有时真不知该写什么好.那天无意中发 ...

  7. HTML5:一个拖拽网页元素的例子

    关键字:HTML5, Drag&Drop, JavaScript, CSS 运行环境:Chrome <!DOCTYPE html> <html> <head> ...

  8. jquery直接获取html页面元素

    大家都会用$('div')来获取div并对其进行一些操作,今天用到一个函数发现$('div')与getElementBy系列函数得到的对象并不一样. 然后去查了下,发现$('div')得到的是一个数组 ...

  9. 黑马程序员-------.net基础知识三

    条件执行语句 if 语句 语法: [csharp] view plaincopyprint? if(条件) { 语句1;语句2:语句3: ··· } 执行过程: 先判断条件是否为true ,如果为tr ...

  10. xcode升级后, 插件失效修复

    1. 首先查看 Xcode 的 UUID,在终端执行 defaults read /Applications/Xcode.app/Contents/Info DVTPlugInCompatibilit ...