首先要回顾一下indexOf和lastIndexOf的用法http://blog.csdn.net/caoxu1987728/archive/2008/04/17/2300447.aspx
找到太平洋手机主页的源文件中的代码,从而获得如下内容
经过整理如下:
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中
抓取清单代码
{
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
由于刚开始的时候,没有自己整理一直出错,后来我就想怎样才能不需要要整理就可以一句一句读出呢?终于写了一个,呵呵,挺简单的
{
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