get the header content from some website, in java

本文提供了一段Java代码示例,用于从指定网站抓取页面头部的元数据信息。通过解析HTTP响应头,该代码能够提取<meta>标签内容,并展示了一个具体实例。

just help one friend for writing some java code to access the meta data of the header of some website's response:

 

=====================================

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

 

public class ReadWebsite {

 /**
  * @param args
  */
 public static void main(String[] args) {
  int READ_BUFFER_SIZE = 1024;
  
  try
  {
   //make change to a different website, please edit here!
      //URL url = new URL("http://www.google.com/");
   URL url = new URL("http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html");
  
      URLConnection urlConnection = url.openConnection();
      InputStream ins = urlConnection.getInputStream();     
      InputStreamReader i = new InputStreamReader(ins);

      BufferedReader b = new BufferedReader(new InputStreamReader(ins));
      String oneLine = "", content = "", oneField;
    
      while ((oneLine = b.readLine()) != null)
      {
       content += oneLine;
      }     
     
      int start = -1, end = -1;
     
      content = content.toUpperCase();
     
      start = content.indexOf("<META");       
   
      while (start != -1)
      { 
       content = content.substring(start);
       
       end = content.indexOf(">");
       if (end != -1)
       {
        oneField = content.substring(0, end + 1);
        System.out.println("/n");
        System.out.println(oneField);
        
        content = content.substring(end + 1);
       }
       
       start = content.indexOf("<META");
      }        
  }
  catch (IOException e)
  {
   System.err.println("Error: " + e);
  }
  
 }

}

 

 

======== output is as follows:

 

<META NAME="COLLECTION" CONTENT="API">


<META NAME="KEYWORDS" CONTENT="JAVA.LANG.STRING CLASS">


<META NAME="KEYWORDS" CONTENT="CASE_INSENSITIVE_ORDER">


<META NAME="KEYWORDS" CONTENT="LENGTH()">


<META NAME="KEYWORDS" CONTENT="CHARAT()">


<META NAME="KEYWORDS" CONTENT="GETCHARS()">


<META NAME="KEYWORDS" CONTENT="GETBYTES()">


<META NAME="KEYWORDS" CONTENT="EQUALS()">


<META NAME="KEYWORDS" CONTENT="CONTENTEQUALS()">


<META NAME="KEYWORDS" CONTENT="EQUALSIGNORECASE()">


<META NAME="KEYWORDS" CONTENT="COMPARETO()">


<META NAME="KEYWORDS" CONTENT="COMPARETOIGNORECASE()">


<META NAME="KEYWORDS" CONTENT="REGIONMATCHES()">


<META NAME="KEYWORDS" CONTENT="STARTSWITH()">


<META NAME="KEYWORDS" CONTENT="ENDSWITH()">


<META NAME="KEYWORDS" CONTENT="HASHCODE()">


<META NAME="KEYWORDS" CONTENT="INDEXOF()">


<META NAME="KEYWORDS" CONTENT="LASTINDEXOF()">


<META NAME="KEYWORDS" CONTENT="SUBSTRING()">


<META NAME="KEYWORDS" CONTENT="SUBSEQUENCE()">


<META NAME="KEYWORDS" CONTENT="CONCAT()">


<META NAME="KEYWORDS" CONTENT="REPLACE()">


<META NAME="KEYWORDS" CONTENT="MATCHES()">


<META NAME="KEYWORDS" CONTENT="REPLACEFIRST()">


<META NAME="KEYWORDS" CONTENT="REPLACEALL()">


<META NAME="KEYWORDS" CONTENT="SPLIT()">


<META NAME="KEYWORDS" CONTENT="TOLOWERCASE()">


<META NAME="KEYWORDS" CONTENT="TOUPPERCASE()">


<META NAME="KEYWORDS" CONTENT="TRIM()">


<META NAME="KEYWORDS" CONTENT="TOSTRING()">


<META NAME="KEYWORDS" CONTENT="TOCHARARRAY()">


<META NAME="KEYWORDS" CONTENT="VALUEOF()">


<META NAME="KEYWORDS" CONTENT="COPYVALUEOF()">


<META NAME="KEYWORDS" CONTENT="INTERN()">

 

Currently You are now a website builder. These are the code in my cart.php & functions.php. Currently, i am very satisfied with my layout. However, I want to achieve cart like Shopee / Taobao / Lazada, that allow my customer to 1) Do selective checkout, where only selected items are sent to checkout page, and after order created, only these items will be removed from cart. On the other side, non-selected items are retained inside cart, until customer remove them manually through 清除購物車 / 移除選中商品 or customer check out them. Only remove when order is created. If customer go back from checkout page or payment page, or anything, as long as order is not created, dont remove them. Currently im using restore cart way to achieve this, but everything from cart is removed currently after order created. theres some mistake that stop me from achieving this. I turned on feature where customer can see how many items are inside cart through the cart icon at header. At the same time, i dont want my customer to notice that their cart is cleared and recovered before (the amount of items in cart icon will show 0 when havent recover and the number of items after recover). I dont want them to notice the change, therefore, we have to recover it fast until customer did not notice them. Please be considerate regarding customer that use PC because they might access my website through another tab, at there, they can see the amount of items in cart icon. Therefore, i want it to always show the correct amount, only remove when the order is created and maintain if the order is not created. I dont want them to notice how it works (recovering) 2) All these 全选 刪除選中的商品 清空購物車 输入优惠券代码 应用优惠券 已选商品: 0 件,共计: RM0.00 结算 works perfectly fine, please remain them. Maintaining all the layout and achieved functions. Please check which part stopped me from achieving the selective checkout (maintain non-selected items inside cart, only remove selected to checkout items when order created, and dont let customer nmotice the change in their cart. I want them to no matter access from where, either new tab, other device etc, they will see the correct items in their cart) For now, If i cancel the payment halfway, i am logged out when back from payment page, and when i check from other tab, non-selected items are removed from cart, only selected items are still inside cart. Also, when i login back after payment page, it redirects me to pay-only page. Please refer how taobao cart works, and review which part is stopping me from achieve taobao cart, give me the part of code to be changed and the new code to replaced with the current one, as i have no coding basic
08-31
豌豆代理(又称豌豆 IP)是一款一站式国内代理 IP 服务平台,主打高匿名、低延迟、高可用的 IP 资源,支持 HTTP/HTTPS/SOCKS5 协议,适配 Windows、Mac、Android、iOS 多平台。 多类型 IP 资源与高覆盖节点 提供动态住宅 IP、静态独享 IP、数据中心 IP,覆盖全国 200 + 城市,可用率 99%+;支持省市精准选择或全国混拨,适配不同业务合规与稳定性需求。 使用:在客户端 “节点 / 线路” 页,按城市 / 类型筛选,一键连接目标 IP,适合爬虫、电商多账号运营等场景。 秒级 IP 切换与灵活调度 支持手动一键切换、秒级动态切换(切换速度低至 100ms)、定时切换(自定义时长),并自动过滤重复 IP,避免重复使用导致风险。 使用:在 “设置” 中开启 “自动切换” 并设时间间隔,或按 Ctrl+Q 快捷键一键换 IP,适配反爬虫、批量测试等高频切换场景。 全协议支持与多端适配 兼容 HTTP/HTTPS/SOCKS5 主流代理协议,可对接浏览器、爬虫脚本、客户端软件;支持 Windows、Mac、安卓、iOS 多端同步使用,跨设备无缝切换。 使用:在客户端 “协议设置” 选择对应协议,生成代理地址与端口,直接填入目标软件即可生效。 隐私安全与数据加密 自研传输加密技术保护数据传输,搭配高匿名 IP 隐藏真实地址,同时支持自动清除 Cookie / 缓存,降低隐私泄露与追踪风险。 使用:在 “安全设置” 中开启 “数据加密” 与 “自动清理缓存”,公共 WiFi 环境下优先启用,提升隐私防护等级。 智能筛选与稳定网络优化 系统自动筛选低延迟、高可用 IP,过滤失效 / 重复地址;依托自建纯净机房与独享带宽,搭配 BGP 多线接入,保障连接稳定性与速度。 使用:无需手动配置,客户端默认智能匹配合适节点,复杂网络环境可在 “网络
在网络高速发展的时代,众多的软件被开发出来,给用户带来了很大的选择余地,而且人们越来越追求更个性的需求。在这种时代背景下,商家只能以用户为导向,以商品的持续创新作为商家最重要的事项。 在新发展的时代,人们对幼儿资源互助共享平台越来越重视,才能实现幼儿资源互助共享平台的有效发挥,本文将通过幼儿资源互助共享平台的信息,分析在日常生活中对幼儿资源互助共享平台存在哪些问题探讨出进一步提升效率,管理能力的对策。 系统采用了Java技术,将所有模块采用以浏览器交互的模式,选择MySQL作为系统的数据库,来进行系统的设计。基本实现了幼儿资源互助共享平台应有的主要功能模块,本系统有管理员:首页、个人中心、用户管理、卖家管理、咨询师管理、萌宝信息管理、幼儿知识管理、保姆推荐管理、音频资源管理、二手商品管理、商品分类管理、资源分类管理、交流论坛、系统管理,用户;首页、个人中心、萌宝信息管理、保姆推荐管理、音频资源管理,卖家;首页、个人中心、二手商品管理、订单管理,咨询师;首页、个人中心、幼儿知识管理,前台首页;首页、萌宝信息、幼儿知识、保姆推荐、音频资源、二手商品、交流论坛、个人中心、后台管理、购物车等功能。 对系统进行测试后,改善了程序逻辑和代码。同时确保系统中所有的程序都能正常运行,所有的功能都能操作,本系统的开发获取幼儿资源互助共享平台信息能够更加方便快捷,同时也使幼儿资源互助共享平台信息变的更加系统化、有序化。系统界面较友好,易于操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值