现在的位置: 首页 > 综合 > 正文

解析获得的域名

2013年04月26日 ⁄ 综合 ⁄ 共 5114字 ⁄ 字号 评论关闭

首先要回顾一下indexOf和lastIndexOf的用法http://blog.csdn.net/caoxu1987728/archive/2008/04/17/2300447.aspx

找到太平洋手机主页的源文件中的代码,从而获得如下内容

/** * 本页面生成一段javascript,用于生成 产品库品牌 下拉框选项 * @param tag 需要设置的下拉框名称 * @param selected 设置下拉选项后需要直接选中的选项值 * @param keep 保留原下拉框中的多少项(一般可设1,默认为0) * @param pid 产品分类的父类ID * @param useCache 大于0--是使用缓存,否则不使用缓存 * @param jump true:历史分类的ID为负数 * @param showArtPic 大于0--只显示有图片的分类 * @param showall 0:NORMAL;1:ALL;2:NORMAL and SHOP; */ var selectTag = document.getElementById(new String("_jumpbrandList_")); selectTag.options.length=parseInt("1"); selectTag.options.add(new Option("手机通讯","24346")); selectTag.options.add(new Option("数码产品","20805")); selectTag.options.add(new Option("数码配件","35251")); selectTag.options.add(new Option("笔记本","35310")); selectTag.options.add(new Option("整机类","20795")); selectTag.options.add(new Option("电脑配件","20796")); selectTag.options.add(new Option("数字家电","39955")); selectTag.options.add(new Option("外设","20799")); selectTag.options.add(new Option("扩展配件","26672")); selectTag.options.add(new Option("服务器","39617")); selectTag.options.add(new Option("网络设备","20800")); selectTag.options.add(new Option("无线网络","39355")); selectTag.options.add(new Option("办公设备","20798")); selectTag.options.add(new Option("数字音视频","26171")); selectTag.options.add(new Option("耗材","20801")); selectTag.options.add(new Option("汽车电子","42356")); selectTag.options.add(new Option("软件","20797")); selectTag.options.add(new Option("维修维护","44193")); selectTag.options.add(new Option("其他","20803"));

经过整理如下:

 

selectTag.options.add(new Option("手机通讯","24346")); 
selectTag.options.add(
new Option("数码产品","20805")); 
selectTag.options.add(
new Option("数码配件","35251")); 
selectTag.options.add(
new Option("笔记本","35310")); 
selectTag.options.add(
new Option("整机类","20795")); 
selectTag.options.add(
new Option("电脑配件","20796")); 
selectTag.options.add(
new Option("数字家电","39955")); 
selectTag.options.add(
new Option("外设","20799")); 
selectTag.options.add(
new Option("扩展配件","26672")); 
selectTag.options.add(
new Option("服务器","39617"));
 selectTag.options.add(
new Option("网络设备","20800"));
selectTag.options.add(
new Option("无线网络","39355")); 
selectTag.options.add(
new Option("办公设备","20798")); 
selectTag.options.add(
new Option("数字音视频","26171")); 
selectTag.options.add(
new Option("耗材","20801")); 
selectTag.options.add(
new Option("汽车电子","42356"));
 selectTag.options.add(
new Option("软件","20797")); 
selectTag.options.add(
new Option("维修维护","44193"));
selectTag.options.add(
new Option("其他","20803"));

保存在D://test.txt中

抓取清单代码

public static void main(String[]args)throws Exception
    {
        String prefix
="http://pdlib.pconline.com.cn/product/outer.do?method=brand*typeId=";
        BufferedReader reader
=new BufferedReader(new FileReader("d://test.txt"));
        String line
=reader.readLine();
        
while(line!=null)
        {
            String id
=line.substring(line.indexOf(",")+2,line.lastIndexOf("""));  
            System.out.println(prefix
+id);
            
            
            line
=reader.readLine();
        }
    }

得到如下结果:

http://pdlib.pconline.com.cn/product/outer.do?method=brand&typeId=24346
http://pdlib.pconline.com.cn/product/outer.do?method=brand&typeId=20805
http://pdlib.pconline.com.cn/product/outer.do?method=brand&typeId=35251
http://pdlib.pconline.com.cn/product/outer.do?method=brand&typeId=35310
http://pdlib.pconline.com.cn/product/outer.do?method=brand&typeId=20795
http://pdlib.pconline.com.cn/product/outer.do?method=brand&typeId=20796
http://pdlib.pconline.com.cn/product/outer.do?method=brand&typeId=39955
http://pdlib.pconline.com.cn/product/outer.do?method=brand&typeId=20799
http://pdlib.pconline.com.cn/product/outer.do?method=brand&typeId=26672
http://pdlib.pconline.com.cn/product/outer.do?method=brand&typeId=39617
http://pdlib.pconline.com.cn/product/outer.do?method=brand&typeId=20800
http://pdlib.pconline.com.cn/product/outer.do?method=brand&typeId=39355
http://pdlib.pconline.com.cn/product/outer.do?method=brand&typeId=20798
http://pdlib.pconline.com.cn/product/outer.do?method=brand&typeId=26171
http://pdlib.pconline.com.cn/product/outer.do?method=brand&typeId=20801
http://pdlib.pconline.com.cn/product/outer.do?method=brand&typeId=42356
http://pdlib.pconline.com.cn/product/outer.do?method=brand&typeId=20797
http://pdlib.pconline.com.cn/product/outer.do?method=brand&typeId=44193
http://pdlib.pconline.com.cn/product/outer.do?method=brand&typeId=20803

由于刚开始的时候,没有自己整理一直出错,后来我就想怎样才能不需要要整理就可以一句一句读出呢?终于写了一个,呵呵,挺简单的

public static void main(String[]args)throws Exception
    {
        String prefix
="http://pdlib.pconline.com.cn/product/outer.do?method=brand*typeId=";
        BufferedReader reader
=new BufferedReader(new FileReader("d://test.txt"));
        String line
=reader.readLine();
        
while(line!=null)
        {
            String id
=null;
            
int fromIndex=0;
            
while((fromIndex=line.indexOf(",",fromIndex+1))!=-1
            {
                String id
=line.substring(fromIndex+2,fromIndex+7);  //,line.lastIndexOf(""")
                System.out.println(prefix+id);
            }
            
            line
=reader.readLine();
        }
    }

一个一个代码读过去,可能效率很低,不过没办法,技术有限啊

注:没整理时候,整个文本在读取的时候就一行,不知道为什么

OK

抱歉!评论已关闭.