?? pageoperate.java
字號:
for (int shuh = 1; shuh < splitHtmlUsehref.length; shuh++)
{
String oneHttp=splitHtmlUsehref[shuh];
int beginIndex=0;
int endIndex=0;
int max=200;
//去掉第一個不是正常字母的字符
while(oneHttp.startsWith("\"", 0) || oneHttp.startsWith("'", 0)|| oneHttp.startsWith("/", 0) )//第一個字符是雙引號開始 或著單引號
{
//System.out.println("-------"+splitHtmlUsehref[shuh]);
beginIndex=1;
endIndex=(splitHtmlUsehref[shuh].length()-1);
oneHttp=http(beginIndex, endIndex, oneHttp);//先從空格處斷開
//System.out.println("-------oneHttp:"+oneHttp);
}
if(oneHttp.startsWith("http://", 0))
{
String oldHtml=oneHttp;
oneHttp=null;
beginIndex=0;
endIndex=oldHtml.indexOf(' ');
if(endIndex!=-1 && endIndex<max)//有空格
{
oneHttp=http(beginIndex, endIndex, oldHtml);//從空格處斷開
endIndex=oneHttp.indexOf('"'); endIndex=oneHttp.indexOf('"');
if(endIndex!=-1 && endIndex<max)//有雙引號
{
oneHttp=http(beginIndex, endIndex, oneHttp);//從雙引號處斷開
}
endIndex=oneHttp.indexOf(')');
if(endIndex!=-1 && endIndex<max)//有)號
{
oneHttp=http(beginIndex, endIndex, oneHttp);//從)號處斷開
}
endIndex=oneHttp.indexOf('>');
if(endIndex!=-1 && endIndex<max)//有)號
{
oneHttp=http(beginIndex, endIndex, oneHttp);//從)號處斷開
}
endIndex=oneHttp.indexOf("'");
if(endIndex!=-1 && endIndex<max)//有'號
{
oneHttp=http(beginIndex, endIndex, oneHttp);//從)號處斷開
}
}
else //沒有空格
{
//System.out.println("沒有空格或字符串>200");
}
if(oneHttp!=null)
{
myHttpList.add(oneHttp);
//System.out.println("http://"+oneHttp);
}
}
}//end for
}//end if
}//end public
public List getMyListHttp()// 返回一個List,其中保存了被分割的片段
{
return myHttpList;
}
public boolean hasForm()
{
if(myHtml!=null)
{
String[] chechSearchHtml=myHtml.split("<form");//檢測是否有查詢接口
int splitChechSearchHtml=chechSearchHtml.length;
//System.out.println("用form分割myHtml后有:"+splitChechSearchHtml+"段");
if(splitChechSearchHtml>=2)//有表單
{
return true;
}
else
{
//System.out.println("沒有form表單:");
return false;
}
}
else
{
System.out.println("myHtml是空的");
return false;
}
}
//分析一個baidu結果網頁,從中找下一頁的url
public String nextPageUrl(String httpPrefix,String splitWord,String nextPageWord)
{
String url="";
if (myHtml != null)
{
String[] splitHtmlUsehref = myHtml.split(splitWord); // href=切割// 用到了上面定義的myHtml
for (int shuh = 1; shuh < splitHtmlUsehref.length; shuh++)
{
if(splitHtmlUsehref[shuh].indexOf("下一頁")!=-1)//是否包含下一頁
{
String oneHttp=splitHtmlUsehref[shuh];
int beginIndex=0;
int endIndex=0;
int max=200;
//去掉第一個不是正常字母的字符
while(oneHttp.startsWith("\"", 0) || oneHttp.startsWith("'", 0)|| oneHttp.startsWith("/", 0) )//第一個字符是雙引號開始 或著單引號
{
//System.out.println("-------"+splitHtmlUsehref[shuh]);
beginIndex=1;
endIndex=(splitHtmlUsehref[shuh].length()-1);
oneHttp=http(beginIndex, endIndex, oneHttp);//先從空格處斷開
//System.out.println("-------oneHttp:"+oneHttp);
}
//首先提取沒有http://的代碼
if(!oneHttp.startsWith("http://",0 ))//沒有http://
{
beginIndex=0;
endIndex=splitHtmlUsehref[shuh].indexOf(' ');
if(endIndex!=-1 && endIndex<max)//有空格
{
oneHttp=http(beginIndex, endIndex, oneHttp);//先從空格處斷開
beginIndex=0;//已經把第一個字符去掉了,所以必須的從0開始
endIndex=oneHttp.indexOf('"', 1); endIndex=oneHttp.indexOf('"');
if(endIndex!=-1 && endIndex<max)//有雙引號
{
oneHttp=http(beginIndex, endIndex, oneHttp);//從雙引號處斷開
}
endIndex=oneHttp.indexOf(')');
if(endIndex!=-1 && endIndex<max)//有)號
{
oneHttp=http(beginIndex, endIndex, oneHttp);//從)號處斷開
}
endIndex=oneHttp.indexOf('>');
if(endIndex!=-1 && endIndex<max)//有)號
{
oneHttp=http(beginIndex, endIndex, oneHttp);//從)號處斷開
}
endIndex=oneHttp.indexOf("'",1);
if(endIndex!=-1 && endIndex<max)//有'號
{
oneHttp=http(beginIndex, endIndex, oneHttp);//從)號處斷開
}
}//end 有空格
else //沒有空格
{
System.out.println("沒有空格或字符串>200");
}
if(oneHttp!=null)
{
url=httpPrefix+oneHttp;
System.out.println(url);//他的前綴是http://www.baidu.com/
}
}
}//end 是否包含下一頁
}
}
return url;
}
public boolean hasTextAndSearch()
{
if (myHtml != null)
{
String[] text1=myHtml.split("type=text");
String[] text2=myHtml.split("type=\"text\"");
String[] text3=myHtml.split("type=\'text\'");
String[] text4=myHtml.split("class=\"textbox\"");
String[] text5=myHtml.split("class=textbox");
String[] text6=myHtml.split("class=\'textbox\'");
int text=text1.length+text2.length+text3.length+text4.length+text5.length+text6.length;
if(text>6 && myHtml.indexOf("search")!=-1 )
{
System.out.println("網頁中有文本框和搜索字樣");
return true;
}
else
{
System.out.println("網頁中沒有文本框和搜索字樣");
}
}
return false;
}
public void charSet()
{
if(myHtml!=null)
{
try
{
if(myHtml.indexOf("charset=utf-8")!=-1 || myHtml.indexOf("charset='utf-8'")!=-1 || myHtml.indexOf("charset=\"utf-8\"")!=-1)
{
myHtml=new String(myHtml.getBytes("GBK"),"utf-8");
}
else if(myHtml.indexOf("charset=iso8859_1")!=-1 || myHtml.indexOf("charset='iso8859_1'")!=-1 || myHtml.indexOf("charset=\"iso8859_1\"")!=-1)
{
myHtml=new String(myHtml.getBytes("GBK"),"iso8859_1");
}
else
{
System.out.println("字符不需要轉換");
}
}
catch(Exception e)
{
System.out.println("字符轉換出現異常");
e.printStackTrace();
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -