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. 疯狂学习java web

    因工作需要,疯狂学习java web,只是这么多年一直从事C++开发,突然之间要接手同事的那么一大堆代码,真有无从下手的感觉,首先是要学习html,然后是js, 然后是jsp,当然还有各种框架,想想就 ...

  2. 检测 IE 版本 in Javascript

    点击打开链接http://stackoverflow.com/questions/10964966/detect-ie-version-in-javascript <!doctype html& ...

  3. wamp配置

    # #localhost # <VirtualHost *:> DocumentRoot "D:/software/wamp/www" ServerName local ...

  4. js之封装sort实现json格式数据的排序

    eg  : data:{[ {"name":"paul","ege":12}, {"name":"paul&q ...

  5. demo_06Canvas

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. SVG绘制矩形简单示例分享

    最近我初学HTML5,刚在一步步学习SVG,积累了一些个人心得和程序代码,希望和大家分享,今天分享“svg之矩形”部分 1.简单矩形 效果图如下: 关键代码: <svg xmlns=" ...

  7. css动画怎么写:3个属性实现

    3个属性:transition,animation,transform 实现步骤: 1.css定位 2.rgba设置颜色透明度 3.转换+动画 transform+animation 4.动画平滑过渡 ...

  8. Linux grep和find的区别

    这是两个不同的命令,关于grep:Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来.grep全称是Global Regular Expressi ...

  9. CPU/寄存器/内存

    因为要了解多线程,自然少不了一些硬件知识的科普,我没有系统学习过硬件知识,仅仅是从书上以及网络上看来的,如果有错误请指出来. CPU,全名Central Processing Unit(中央处理器). ...

  10. shell编程的一些例子2

    控制语句: 1.if语句 demo_if #!/bin/bash if [ $# -ne 1 ] then echo "参数多于一个" exit 1 fi if [ -f &quo ...