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. 页面mask css

    <html> <head> <style type="text/css"> .share_mask { position: fixed; top ...

  2. scala - 从合并两个Map说开去 - foldLeft 和 foldRight 还有模式匹配

    开发中遇到需求:合并两个Map集合对象(将两个对应KEY的值累加) 先说解决方案: ( map1 )) ) } 这特么什么鬼  (╯‵□′)╯""┻━┻☆))>○<)  ...

  3. Docker命令使用详解

    其中<>括起来的参数为必选, []括起来为可选 docker -exec -i -t 3f407013d8c0 /bin/bash    进入容器 docker version查看dock ...

  4. 一个供新手把玩的jQueryUI在线文档

    最近整理了一份jQueryUI文档,方便以后学习和运用. 把玩地址

  5. C#基础(二)——C#中的构造函数

    构造函数主要是用来创建对象时为对象赋初值来初始化对象.总与new运算符一起使用在创建对象的语句中 .A a=new A(); 构造函数具有和类一样的名称:但它是一个函数具有函数的所有特性,同一个类里面 ...

  6. [C#]『CountdownEvent』任务并行库使用小计

    System.Threading.CountdownEvent  是一个同步基元,它在收到一定次数的信号之后,将会解除对其等待线程的锁定. CountdownEvent  专门用于以下情况:您必须使用 ...

  7. React组件三

    <script> <!-- getDefalutPros 设置组件的默认值--> <!--var Mytitle=React.createClass({ getDefau ...

  8. React新接触

    html5页面的开始引入: <script src="../build/react.js"></script>   <!--核心库--> < ...

  9. JavaScript原型链demo

    function Person(name){ this.name = name; } Person.prototype = { say: function(){ alert('hi'); }, say ...

  10. skymvc网站测试之mysql数据生成

    skymvc网站测试之mysql数据生成 使用方法: 删除数据 /index.php?m=test_mysql&a=autoDelete 重置自增ID /index.php?m=test_my ...