C#实现web信息抓取

 

None.gif 随着Internet的普及,网络信息正以极高的速度增长,在这么多数据中找到自己需要的信息是一件很繁琐的事情,找到需要的信息后如何获取也是件麻烦的事。这就需要Internet信息抓取程序来代替人工的操作。
None.gif            所谓Internet信息抓取程序,就是程序会按照用户的关键词或关键网站来收集相应的信息,并提供给用户想要的信息格式。
None.gif            信息量的增加会带来信息网站发布人员工作量的剧增,为实现信息发布系统实现信息自
None.gif            动发布、减少工作人员工作量、即时跟踪最新信息,就需要自动信息提供程序,因此Internet信息抓取程序应运而生。
None.gif             
None.gif            目标
None.gif
None.gif            实现自定义网站信息分类抓取,存入本地数据库、生成静态页面或其它用户定义的信息结构,并下载与信息相关的多媒体文件。
None.gif             
None.gif            开发
None.gif             
None.gif            l         目标站点结构分析
None.gif            本步骤是准确抓取信息个关键。
None.gif            首先要选择更新频率高的页面做为抓取地址,然后分析要抓取内容页面url特点。
None.gif            然后分析要抓取信息页面的元素特性,比如标题位置,内容位置 等,得到定位标记点。
None.gif            将以上信息写成自己的配置文件或存到数据库中。
None.gif            每个网站都需要分析,写出单独的配置文件,供抓取程序使用。
None.gif             
None.gif            l         信息提取
None.gif            根据配置文件取得要抓取页面url,使用HttpWebRequest类获取内容:
None.gif
None.gif            
// 获取http页面函数
None.gif

None.gif                    
public   string  Get_Http( string  a_strUrl, int  timeout)
None.gif
ExpandedBlockStart.gifContractedBlock.gif                    
dot.gif {
InBlock.gif
InBlock.gif                        
string strResult ;         
InBlock.gif
InBlock.gif             
InBlock.gif
InBlock.gif                        
try
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif
InBlock.gif            HttpWebRequest myReq 
= 
InBlock.gif            (HttpWebRequest)HttpWebRequest.Create(a_strUrl) ;
InBlock.gif
InBlock.gif                            myReq.Timeout 
= timeout;
InBlock.gif
InBlock.gif                            HttpWebResponse HttpWResp 
= 
InBlock.gif            (HttpWebResponse)myReq.GetResponse();
InBlock.gif
InBlock.gif                        
InBlock.gif
InBlock.gif                            Stream myStream 
= HttpWResp.GetResponseStream () ;
InBlock.gif
InBlock.gif             
InBlock.gif
InBlock.gif                            StreamReader sr 
= new StreamReader(myStream , 
InBlock.gif            Encoding.Default);
InBlock.gif
InBlock.gif                            StringBuilder strBuilder 
= new StringBuilder();
InBlock.gif
InBlock.gif                            
while (-1 != sr.Peek())
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                strBuilder.Append(sr.ReadLine()
+"\r\n");
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif             
InBlock.gif
InBlock.gif                            strResult 
= strBuilder.ToString();
InBlock.gif
ExpandedSubBlockEnd.gif                        }

InBlock.gif
InBlock.gif                        
catch(Exception exp)
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif
InBlock.gif                            strResult 
= "错误:" + exp.Message ;
InBlock.gif
ExpandedSubBlockEnd.gif                        }

InBlock.gif
InBlock.gif             
InBlock.gif
InBlock.gif                        
return strResult ;
InBlock.gif
InBlock.gif             
InBlock.gif
ExpandedBlockEnd.gif                    }

None.gif
None.gif            获取页面内容后,分析页面中连接地址取到要抓取的url:
None.gif
None.gif            
// 处理页面标题和链接
None.gif

None.gif                    
public   string  SniffWebUrl(  string  urlStr, string  
None.gif            blockB,
string  blockE )
None.gif
ExpandedBlockStart.gifContractedBlock.gif                    
dot.gif {       
InBlock.gif
InBlock.gif                        
string urlch1 = "";
InBlock.gif
InBlock.gif                        
string urlch2 = "";                    
InBlock.gif
InBlock.gif                        
int end_n1 = 0;
InBlock.gif
InBlock.gif                        
int end_nums = 0;
InBlock.gif
InBlock.gif                        
int end_nums1 = 0;
InBlock.gif
InBlock.gif                        
int end_nums2 = 0;
InBlock.gif
InBlock.gif                        
int end_nums3     = 0;            
InBlock.gif
InBlock.gif                        
string reUTStr = "";
InBlock.gif
InBlock.gif                        
string reTitle = "";
InBlock.gif
InBlock.gif                        
string ret = "";           
InBlock.gif
InBlock.gif                        
try
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif
InBlock.gif                            
int pos01 = urlStr.IndexOf( "." );
InBlock.gif
InBlock.gif                            
int pos02 = urlStr.LastIndexOf( "/" );
InBlock.gif
InBlock.gif                            
if( pos01 < 0 ) 
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                
return "";
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif                            
if( pos02 < 0 ) 
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                
return "";
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif                            
int pos03 = urlStr.IndexOf( "/",pos01 );
InBlock.gif
InBlock.gif                            
if ( pos03 < 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                urlch1 
= urlStr;
InBlock.gif
InBlock.gif                                urlch2 
= urlStr;
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif                            
else
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                urlch1 
= urlStr.Substring( 0,pos03 );
InBlock.gif
InBlock.gif                                urlch2 
= urlStr.Substring( 0,pos02 );
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif             
InBlock.gif
InBlock.gif                            
string tmpAllStr = new PublicFun().Get_Http( urlStr 
InBlock.gif            ,time1);
InBlock.gif
InBlock.gif             
InBlock.gif
InBlock.gif                            
int pos1 = tmpAllStr.IndexOf( blockB );
InBlock.gif
InBlock.gif                            
int pos2 = tmpAllStr.IndexOf( blockE,pos1 + 
InBlock.gif            blockB.Length );
InBlock.gif
InBlock.gif                            
if ( pos1>0 && pos2>0 && pos2>pos1 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                ret 
= tmpAllStr.Substring( pos1 + 
InBlock.gif            blockB.Length,pos2 
- pos1 - blockB.Length );
InBlock.gif
InBlock.gif                                ret 
= ret.Substring( ret.IndexOf( "<" ));
InBlock.gif
InBlock.gif                                
while( ret.IndexOf( "<A" ) >= 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{
InBlock.gif
InBlock.gif                                    ret 
= ret.Substring( 0,ret.IndexOf( "<A" ) ) 
InBlock.gif            
+ "<a" + ret.Substring( ret.IndexOf( "<A" ) + 2 );
InBlock.gif
ExpandedSubBlockEnd.gif                                }

InBlock.gif
InBlock.gif                                
while( ret.IndexOf( "</A" ) >=0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{
InBlock.gif
InBlock.gif                                    ret 
= ret.Substring( 0,ret.IndexOf( "</A" ) 
InBlock.gif            ) 
+ "</a" + ret.Substring( ret.IndexOf( "</A" ) + 3 );
InBlock.gif
ExpandedSubBlockEnd.gif                                }

InBlock.gif
InBlock.gif                                
while( ret.IndexOf( "Href=" ) >=0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{
InBlock.gif
InBlock.gif                                    ret 
= ret.Substring( 0,ret.IndexOf( "Href=" 
InBlock.gif            )) 
+ "href=" + ret.Substring( ret.IndexOf( "Href=" ) + 5 );
InBlock.gif
ExpandedSubBlockEnd.gif                                }

InBlock.gif
InBlock.gif                                
while( ret.IndexOf( "HREF=" ) >=0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{
InBlock.gif
InBlock.gif                                    ret 
= ret.Substring( 0,ret.IndexOf( "HREF=" 
InBlock.gif            )) 
+ "href=" + ret.Substring( ret.IndexOf( "HREF=" ) + 5 );
InBlock.gif
ExpandedSubBlockEnd.gif                                }

InBlock.gif
InBlock.gif                                
while( ret.IndexOf( "href='" ) >=0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{
InBlock.gif
InBlock.gif                                    ret 
= ret.Substring( 0,ret.IndexOf( "href='" 
InBlock.gif            )) 
+ "href=\"" + ret.Substring( ret.IndexOf( "href='" ) + 6 );
InBlock.gif

ExpandedSubBlockEnd.gif                                }

InBlock.gif
ExpandedSubBlockEnd.gif                            }
       
InBlock.gif
InBlock.gif                            tmpAllStr 
= ret;      
InBlock.gif
InBlock.gif                            
int begin_nums = tmpAllStr.IndexOf( "href=" );
InBlock.gif
InBlock.gif             
InBlock.gif
InBlock.gif                            
while ( begin_nums >= 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{               
InBlock.gif
InBlock.gif                                
string tmpStrA = "";
InBlock.gif
InBlock.gif                                
string tmpStrB = tmpAllStr.Substring( begin_nums 
InBlock.gif            
+ 5,1 );
InBlock.gif
InBlock.gif                                
if ( tmpStrB == "\"" )
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{
InBlock.gif
InBlock.gif                                    end_n1 
= begin_nums + 6;
InBlock.gif
InBlock.gif                                    
if ( ( end_n1 + 1 ) > tmpAllStr.Length )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                    
dot.gif{
InBlock.gif
InBlock.gif                                        
return "";
InBlock.gif
ExpandedSubBlockEnd.gif                                    }

InBlock.gif
InBlock.gif                                    tmpStrA 
= tmpAllStr.Substring( 
InBlock.gif            begin_nums
+6,1 );
InBlock.gif
ExpandedSubBlockEnd.gif                                }

InBlock.gif
InBlock.gif                                
else
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{
InBlock.gif
InBlock.gif                                    end_n1 
= begin_nums + 5;
InBlock.gif
InBlock.gif                                    tmpStrA 
= tmpStrB;
InBlock.gif
ExpandedSubBlockEnd.gif                                }

InBlock.gif
InBlock.gif             
InBlock.gif
InBlock.gif                                
if ( tmpStrA == "#" )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{
InBlock.gif
InBlock.gif                                    tmpAllStr 
= tmpAllStr.Substring( end_n1 );
InBlock.gif
InBlock.gif                                    begin_nums 
= tmpAllStr.IndexOf( "href=" );
InBlock.gif
ExpandedSubBlockEnd.gif                                }

InBlock.gif
InBlock.gif                                
else
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{                   
InBlock.gif
InBlock.gif                                    end_nums1 
= tmpAllStr.IndexOf( " ",end_n1 );
InBlock.gif
InBlock.gif                                    end_nums2 
= tmpAllStr.IndexOf( ">",end_n1 );
InBlock.gif
InBlock.gif                                    end_nums3 
= tmpAllStr.IndexOf( 
InBlock.gif            
"</a",end_nums2 );
InBlock.gif
InBlock.gif             
InBlock.gif
InBlock.gif                                    
if ( ( end_nums3 >= 0 ) && ( end_nums2 >= 0 
InBlock.gif            ) )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                    
dot.gif{
InBlock.gif
InBlock.gif                                        reTitle 
= tmpAllStr.Substring( end_nums2 
InBlock.gif            
+ 1,end_nums3 - end_nums2 - 1 );
InBlock.gif
InBlock.gif             
InBlock.gif
InBlock.gif                                        
if ( end_nums1 > end_nums2 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                        
dot.gif{
InBlock.gif
InBlock.gif                                            end_nums 
= end_nums2;
InBlock.gif
ExpandedSubBlockEnd.gif                                        }

InBlock.gif
InBlock.gif                                        
else
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                        
dot.gif{
InBlock.gif
InBlock.gif                                            
if ( end_nums1 < 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                            
dot.gif{
InBlock.gif
InBlock.gif                                                end_nums 
= end_nums2;
InBlock.gif
ExpandedSubBlockEnd.gif                                            }

InBlock.gif
InBlock.gif                                            
else
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                            
dot.gif{
InBlock.gif
InBlock.gif                                                end_nums 
= end_nums1;
InBlock.gif
ExpandedSubBlockEnd.gif                                            }

InBlock.gif
ExpandedSubBlockEnd.gif                                        }

InBlock.gif
InBlock.gif                                        
string str4 = tmpAllStr.Substring( 
InBlock.gif            end_nums
-1, end_nums - end_nums + 1 );
InBlock.gif
InBlock.gif             
InBlock.gif
InBlock.gif                                        
if ( str4 =="\""  || str4 == "'" )
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif                                        
dot.gif{
InBlock.gif
InBlock.gif                                            end_nums 
= end_nums - 1;
InBlock.gif
ExpandedSubBlockEnd.gif                                        }

InBlock.gif
InBlock.gif                                        
string sTotalOne = tmpAllStr.Substring( 
InBlock.gif            end_n1,end_nums 
- end_n1 );
InBlock.gif
InBlock.gif             
InBlock.gif
InBlock.gif                                        
if ( sTotalOne.IndexOf( "http://" ) <0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                        
dot.gif{
InBlock.gif
InBlock.gif                                            
if ( sTotalOne.IndexOf( "/" ) == 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                            
dot.gif{
InBlock.gif
InBlock.gif                                                sTotalOne 
= urlch1 + sTotalOne;
InBlock.gif
ExpandedSubBlockEnd.gif                                            }

InBlock.gif
InBlock.gif                                            
else
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                            
dot.gif{                               
InBlock.gif
InBlock.gif                                                
int linshiIntNum = 0;
InBlock.gif
InBlock.gif                                                
int flags = 0;
InBlock.gif
InBlock.gif                                                
string urlChange = urlStr;;
InBlock.gif
InBlock.gif                                                
while( sTotalOne.IndexOf( "../" 
InBlock.gif            ) 
>= 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                                
dot.gif{
InBlock.gif
InBlock.gif                                                    sTotalOne 
= 
InBlock.gif            sTotalOne.Substring( sTotalOne.IndexOf( 
"../" ) + 3 );
InBlock.gif
InBlock.gif                                                    linshiIntNum 
= linshiIntNum 
InBlock.gif            
+ 1;
InBlock.gif
InBlock.gif                                                    flags 
= flags +1;
InBlock.gif
ExpandedSubBlockEnd.gif                                                }

InBlock.gif
InBlock.gif                                                
while( ( urlChange.LastIndexOf( 
InBlock.gif            
"/" ) >= 0 ) && ( linshiIntNum >= 0 ) )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                                
dot.gif{
InBlock.gif
InBlock.gif                                                    urlChange 
= 
InBlock.gif            urlChange.Substring( 
0,urlChange.LastIndexOf( "/" ) );
InBlock.gif
InBlock.gif                                                    linshiIntNum 
= linshiIntNum 
InBlock.gif            
- 1;
InBlock.gif
ExpandedSubBlockEnd.gif                                                }

InBlock.gif
InBlock.gif                                                
if ( flags == 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                                
dot.gif{
InBlock.gif
InBlock.gif                                                    sTotalOne 
= urlch2 + "/" + 
InBlock.gif            sTotalOne;
InBlock.gif
ExpandedSubBlockEnd.gif                                                }

InBlock.gif
InBlock.gif                                                
else
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                                
dot.gif{
InBlock.gif
InBlock.gif                                                    sTotalOne 
= urlChange + "/" 
InBlock.gif            
+ sTotalOne;
InBlock.gif
ExpandedSubBlockEnd.gif                                                }

InBlock.gif
ExpandedSubBlockEnd.gif                                            }

InBlock.gif
ExpandedSubBlockEnd.gif                                        }

InBlock.gif
InBlock.gif                                        reUTStr 
= reUTStr + new 
InBlock.gif            PublicFun().RemoveHtmlCode( reTitle ) 
+ sTotalOne;
InBlock.gif
InBlock.gif             
InBlock.gif
InBlock.gif                                        tmpAllStr 
= tmpAllStr.Substring( 
InBlock.gif            end_nums3 
+ 4 );
InBlock.gif
InBlock.gif                                        begin_nums 
= tmpAllStr.IndexOf( "href=" 
InBlock.gif            );
InBlock.gif
ExpandedSubBlockEnd.gif                                    }

InBlock.gif
InBlock.gif                                    
else
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                    
dot.gif{
InBlock.gif
InBlock.gif                                        begin_nums 
= -1;
InBlock.gif
ExpandedSubBlockEnd.gif                                    }
                    
InBlock.gif
ExpandedSubBlockEnd.gif                                }

InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif                            
return reUTStr;
InBlock.gif
ExpandedSubBlockEnd.gif                        }

InBlock.gif
InBlock.gif                        
catch( Exception e)
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif
InBlock.gif                            
return "";
InBlock.gif
ExpandedSubBlockEnd.gif                        }

InBlock.gif
ExpandedBlockEnd.gif                    }

None.gif
None.gif             
None.gif
None.gif            得到要抓取内容的url后,处理该页面:
None.gif
None.gif            
// 获取链接内容并分类处理
None.gif

None.gif                    
public   string  GetWebContent(  string  gatherUrl, string  
None.gif            subUrl,
string  subTitle, string  b_Content, string  e_Content, string  
None.gif            b_Filter,
string  e_Filter, string  root )
None.gif
ExpandedBlockStart.gifContractedBlock.gif                    
dot.gif {
InBlock.gif
InBlock.gif                        
string tmpAllStr = "";            
InBlock.gif
InBlock.gif                        
string dfStrB = "";
InBlock.gif
InBlock.gif                        
string dfStrE = "";                
InBlock.gif
InBlock.gif                        
string rePicStr = "";//图片返回路径    
InBlock.gif

InBlock.gif                        
string reContentStr = "";
InBlock.gif
InBlock.gif                        
string picHtml = "images"//本地图片路径
InBlock.gif

InBlock.gif                        
InBlock.gif
InBlock.gif                        
string urlch1 ="";
InBlock.gif
InBlock.gif                        
string urlch2 ="";
InBlock.gif
InBlock.gif                        
int pos1 = gatherUrl.IndexOf( "." );
InBlock.gif
InBlock.gif                        
int pos2 = gatherUrl.LastIndexOf( "/" );
InBlock.gif
InBlock.gif                        
if( pos1 < 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif
InBlock.gif                            
return "";
InBlock.gif
ExpandedSubBlockEnd.gif                        }

InBlock.gif
InBlock.gif                        
if( pos2 < 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{                
InBlock.gif
InBlock.gif                            
return "";
InBlock.gif
ExpandedSubBlockEnd.gif                        }

InBlock.gif
InBlock.gif                        
int pos3 = gatherUrl.IndexOf( "/",pos1 );
InBlock.gif
InBlock.gif                        
if ( pos3 < 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif
InBlock.gif                            urlch1 
= gatherUrl;
InBlock.gif
InBlock.gif                            urlch2 
= gatherUrl;
InBlock.gif
ExpandedSubBlockEnd.gif                        }

InBlock.gif
InBlock.gif                        
else
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif
InBlock.gif                            urlch1 
= gatherUrl.Substring( 0,pos3 );
InBlock.gif
InBlock.gif                            urlch2 
= gatherUrl.Substring( 0,pos2 );
InBlock.gif
ExpandedSubBlockEnd.gif                        }
    
InBlock.gif
InBlock.gif                        
InBlock.gif
InBlock.gif                        tmpAllStr 
= new PublicFun().Get_Http( subUrl,time1 );
InBlock.gif
InBlock.gif                        
//取稿源
InBlock.gif

InBlock.gif                        
string docFromStr = "";
InBlock.gif
InBlock.gif                        
if ( dfStrB != "" && dfStrE != "" )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif
InBlock.gif                            
if ( tmpAllStr != "" )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                
int b_docF = tmpAllStr.IndexOf( dfStrB );
InBlock.gif
InBlock.gif                                
if ( b_docF > 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{
InBlock.gif
InBlock.gif                                    
int e_docF = tmpAllStr.IndexOf( 
InBlock.gif            dfStrE,b_docF 
+ dfStrB.Length );
InBlock.gif
InBlock.gif                                    
if ( e_docF > 0 && e_docF > b_docF && e_docF 
InBlock.gif            
- b_docF < 20 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                    
dot.gif{
InBlock.gif
InBlock.gif                                        docFromStr 
= tmpAllStr.Substring( b_docF 
InBlock.gif            
+ dfStrB.Length, e_docF - b_docF - dfStrB.Length );
InBlock.gif
ExpandedSubBlockEnd.gif                                    }

InBlock.gif
ExpandedSubBlockEnd.gif                                }

InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
ExpandedSubBlockEnd.gif                        }

InBlock.gif
InBlock.gif                        
//取内容
InBlock.gif

InBlock.gif                        
if ( tmpAllStr != "" )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{                
InBlock.gif
InBlock.gif                            
int begin_strnum = tmpAllStr.IndexOf( b_Content );
InBlock.gif
InBlock.gif                            
if ( begin_strnum < 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{                   
InBlock.gif
InBlock.gif                                
return "";
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif                            
int end_strnum = tmpAllStr.IndexOf( 
InBlock.gif            e_Content,begin_strnum 
+ b_Content.Length );
InBlock.gif
InBlock.gif                            
if ( end_strnum < 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{                   
InBlock.gif
InBlock.gif                                
return "";
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif                            
string sTotalSubM = "";
InBlock.gif
InBlock.gif                            
if ( end_strnum > begin_strnum )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                sTotalSubM 
= tmpAllStr.Substring ( 
InBlock.gif            begin_strnum,end_strnum 
- begin_strnum );
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif                            
InBlock.gif
InBlock.gif                            
if ( sTotalSubM == "" )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{                   
InBlock.gif
InBlock.gif                                
return "";
InBlock.gif
ExpandedSubBlockEnd.gif                            }
               
InBlock.gif
InBlock.gif                            
//过滤无用信息
InBlock.gif

InBlock.gif                            
int bfnum = sTotalSubM.IndexOf( b_Filter );
InBlock.gif
InBlock.gif                            
if ( bfnum > -1 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                
int efnum = sTotalSubM.IndexOf( e_Filter,bfnum 
InBlock.gif);
InBlock.gif
InBlock.gif                                
if ( efnum > -1 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{
InBlock.gif
InBlock.gif                                    
if ( efnum > bfnum )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                    
dot.gif{
InBlock.gif
InBlock.gif                                        sTotalSubM 
= sTotalSubM.Substring( 
InBlock.gif            
0,bfnum ) + sTotalSubM.Substring( efnum + e_Filter.Length );
InBlock.gif
ExpandedSubBlockEnd.gif                                    }

InBlock.gif
ExpandedSubBlockEnd.gif                                }

InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif                            
//格式化图片标记
InBlock.gif

InBlock.gif                            
InBlock.gif
InBlock.gif                            
while( sTotalSubM.IndexOf( "Src=" ) >= 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                sTotalSubM 
= sTotalSubM.Substring( 
InBlock.gif            
0,sTotalSubM.IndexOf( "Src=" ) ) + "src=" + sTotalSubM.Substring( 
InBlock.gif            sTotalSubM.IndexOf( 
"Src=" ) + 4 );
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif                            
while( sTotalSubM.IndexOf( "SRC=" ) >= 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                sTotalSubM 
= sTotalSubM.Substring( 
InBlock.gif            
0,sTotalSubM.IndexOf( "SRC=" ) ) + "src=" + sTotalSubM.Substring( 
InBlock.gif            sTotalSubM.IndexOf( 
"SRC=" ) + 4 );
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif                            
while( sTotalSubM.IndexOf( "src='" ) >= 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                sTotalSubM 
= sTotalSubM.Substring( 
InBlock.gif            
0,sTotalSubM.IndexOf( "src='" ) ) + "src=\"" + sTotalSubM.Substring( 
InBlock.gif
            sTotalSubM.IndexOf( "src='" ) + 5 );
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif             
InBlock.gif
InBlock.gif                            
//取图片地址
InBlock.gif

InBlock.gif                            
int end_n12 = 0;
InBlock.gif
InBlock.gif                            
int end_nums2 = 0;
InBlock.gif
InBlock.gif                            
int begin_nums2 = sTotalSubM.IndexOf( "src=" );
InBlock.gif
InBlock.gif                            
while( begin_nums2 >= 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                String tmpStr 
= sTotalSubM.Substring( 
InBlock.gif            begin_nums2 
+ 4,1 );
InBlock.gif
InBlock.gif                                
if ( tmpStr == "\"" )
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{
InBlock.gif
InBlock.gif                                    end_n12 
= begin_nums2 + 5;
InBlock.gif
ExpandedSubBlockEnd.gif                                }

InBlock.gif
InBlock.gif                                
else
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{
InBlock.gif
InBlock.gif                                    end_n12 
= begin_nums2 + 4;
InBlock.gif
ExpandedSubBlockEnd.gif                                }

InBlock.gif
InBlock.gif                                
int end_nums2a = sTotalSubM.IndexOf( " ",end_n12 
InBlock.gif            );
InBlock.gif
InBlock.gif                                
int end_nums2b = sTotalSubM.IndexOf( ">",end_n12 
InBlock.gif            );
InBlock.gif
InBlock.gif                                
if ( end_nums2b < 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{
InBlock.gif
InBlock.gif                                    
break;
InBlock.gif
ExpandedSubBlockEnd.gif                                }

InBlock.gif
InBlock.gif                                
if ( end_nums2a > end_nums2b )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{
InBlock.gif
InBlock.gif                                    end_nums2 
= end_nums2b;
InBlock.gif
ExpandedSubBlockEnd.gif                                }

InBlock.gif
InBlock.gif                                
else
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{
InBlock.gif
InBlock.gif                                    
if (end_nums2a<0)
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                    
dot.gif{
InBlock.gif
InBlock.gif                                        end_nums2 
= end_nums2b;
InBlock.gif
ExpandedSubBlockEnd.gif                                    }

InBlock.gif
InBlock.gif                                    
else
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                    
dot.gif{
InBlock.gif
InBlock.gif                                        end_nums2 
= end_nums2a;
InBlock.gif
ExpandedSubBlockEnd.gif                                    }

InBlock.gif
ExpandedSubBlockEnd.gif                                }

InBlock.gif
InBlock.gif                                tmpStr 
= sTotalSubM.Substring( end_nums2-1,1 );
InBlock.gif
InBlock.gif                                
if ( tmpStr == "\"" || tmpStr == "'" )
InBlock.gif

ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{
InBlock.gif
InBlock.gif                                    end_nums2 
= end_nums2 - 1;
InBlock.gif
ExpandedSubBlockEnd.gif                                }

InBlock.gif
InBlock.gif                                
string tmpPicStr = sTotalSubM.Substring( 
InBlock.gif            end_n12,end_nums2 
- end_n12 );
InBlock.gif
InBlock.gif             
InBlock.gif
InBlock.gif                                
if ( tmpPicStr.IndexOf( "http://" ) < 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{
InBlock.gif
InBlock.gif                                    
if ( tmpPicStr.IndexOf( "/" ) == 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                    
dot.gif{
InBlock.gif
InBlock.gif                                        tmpPicStr 
= urlch1 + tmpPicStr;
InBlock.gif
ExpandedSubBlockEnd.gif                                    }

InBlock.gif
InBlock.gif                                    
else
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                    
dot.gif{                            
InBlock.gif
InBlock.gif                                        
int linshiIntNum = 0;
InBlock.gif
InBlock.gif                                        
int flags = 0;
InBlock.gif
InBlock.gif                                        
string urlChange = subUrl;
InBlock.gif
InBlock.gif                                        
while( tmpPicStr.IndexOf( "../" ) >= 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                        
dot.gif{
InBlock.gif
InBlock.gif                                            tmpPicStr 
= tmpPicStr.Substring( 
InBlock.gif            tmpPicStr.IndexOf(
"../"+ 3 );
InBlock.gif
InBlock.gif                                            linshiIntNum 
= linshiIntNum + 1;
InBlock.gif
InBlock.gif                                            flags 
= flags + 1;
InBlock.gif
ExpandedSubBlockEnd.gif                                        }

InBlock.gif
InBlock.gif                                        
while( ( urlChange.LastIndexOf( "/" ) >= 
InBlock.gif            
0 ) && ( linshiIntNum >= 0 ) )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                        
dot.gif{
InBlock.gif
InBlock.gif                                            urlChange 
= urlChange.Substring( 
InBlock.gif            
0,urlChange.LastIndexOf( "/" ) );
InBlock.gif
InBlock.gif                                            linshiIntNum 
= linshiIntNum - 1;
InBlock.gif
ExpandedSubBlockEnd.gif                                        }

InBlock.gif
InBlock.gif                                        
if ( flags == 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                        
dot.gif{
InBlock.gif
InBlock.gif                                            tmpPicStr 
= urlch2 + "/" + 
InBlock.giftmpPicStr;
InBlock.gif
ExpandedSubBlockEnd.gif                                        }

InBlock.gif
InBlock.gif                                        
else
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                        
dot.gif{
InBlock.gif
InBlock.gif                                            tmpPicStr 
= urlChange + "/" + 
InBlock.gif            tmpPicStr;
InBlock.gif
ExpandedSubBlockEnd.gif                                        }

InBlock.gif
ExpandedSubBlockEnd.gif                                    }

InBlock.gif
ExpandedSubBlockEnd.gif                                }

InBlock.gif
InBlock.gif                                
//tmpPicStr = tmpPicStr.ToLower();
InBlock.gif

InBlock.gif                                
string tmpPicStrTmp = tmpPicStr.ToLower();
InBlock.gif
InBlock.gif                                
//if ( tmpPicStr.IndexOf( ".jpg" ) > 0 || 
InBlock.gif
            tmpPicStr.IndexOf( ".gif" ) > 0 || tmpPicStr.IndexOf( ".bmp" ) > 0 )
InBlock.gif
InBlock.gif                                
if ( tmpPicStrTmp.IndexOf( ".jpg" ) > 0 || 
InBlock.gif            tmpPicStrTmp.IndexOf( 
".gif" ) > 0 || tmpPicStrTmp.IndexOf( ".bmp" ) 
InBlock.gif            
> 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{
InBlock.gif
InBlock.gif                                    rePicStr 
= rePicStr + "||" + tmpPicStr ;
InBlock.gif
InBlock.gif             
InBlock.gif
InBlock.gif                                    
int flagN2 = tmpPicStr.LastIndexOf( "/" );
InBlock.gif
InBlock.gif                                    
string fileN2 = picHtml + 
InBlock.gif            tmpPicStr.Substring( flagN2 );
InBlock.gif
InBlock.gif                                    sTotalSubM 
= sTotalSubM.Substring( 
InBlock.gif            
0,end_nums2 ) + ">******" + fileN2 + "******<" + 
InBlock.gif            sTotalSubM.Substring( end_nums2 );
InBlock.gif
InBlock.gif             
InBlock.gif
InBlock.gif                                    begin_nums2 
= sTotalSubM.IndexOf( "src="
InBlock.gif            end_nums2 
+ fileN2.Length + 22 );
InBlock.gif
ExpandedSubBlockEnd.gif                                }

InBlock.gif
InBlock.gif                                
else
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{
InBlock.gif
InBlock.gif                                    begin_nums2 
= sTotalSubM.IndexOf( "src="
InBlock.gif            end_nums2 
+ 4 );                        
InBlock.gif
ExpandedSubBlockEnd.gif                                }
                   
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif                            
if ( rePicStr.Length > 2 )  
InBlock.gif
InBlock.gif                                rePicStr 
=  rePicStr.Substring(2);               
InBlock.gif
InBlock.gif
InBlock.gif             
InBlock.gif
InBlock.gif                            
//内容处理 格式化关键标记
InBlock.gif

InBlock.gif                            
while( sTotalSubM.IndexOf( "<P" ) >= 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                sTotalSubM 
= sTotalSubM.Substring( 
InBlock.gif            
0,sTotalSubM.IndexOf( "<P" ) ) + "|****|<" + sTotalSubM.Substring( 
InBlock.gif            sTotalSubM.IndexOf( 
"<P" ) + 2 );
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif                            
while( sTotalSubM.IndexOf( "<p" ) >= 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                sTotalSubM 
= sTotalSubM.Substring( 
InBlock.gif            
0,sTotalSubM.IndexOf( "<p" ) ) + "|****|<" + sTotalSubM.Substring( 
InBlock.gif            sTotalSubM.IndexOf( 
"<p" ) + 2 );
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif                            
while( sTotalSubM.IndexOf( "</P" ) >= 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                sTotalSubM 
= sTotalSubM.Substring( 
InBlock.gif            
0,sTotalSubM.IndexOf( "</P" ) ) + "|****|<" + sTotalSubM.Substring( 
InBlock.gif            sTotalSubM.IndexOf( 
"</P" ) + 3 );
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif                            
while( sTotalSubM.IndexOf( "</p" ) >= 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                sTotalSubM 
= sTotalSubM.Substring( 
InBlock.gif            
0,sTotalSubM.IndexOf( "</p" ) ) + "|****|<" + sTotalSubM.Substring( 
InBlock.gif            sTotalSubM.IndexOf( 
"</p" ) + 3 );
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif                            
while( sTotalSubM.IndexOf( "<br" ) >=0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                sTotalSubM 
= sTotalSubM.Substring( 
InBlock.gif            
0,sTotalSubM.IndexOf( "<br" ) ) + "+****+<" + sTotalSubM.Substring( 
InBlock.gif            sTotalSubM.IndexOf( 
"<br" ) + 3 );
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif                            
while( sTotalSubM.IndexOf( "<BR" ) >= 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                sTotalSubM 
= sTotalSubM.Substring( 
InBlock.gif            
0,sTotalSubM.IndexOf( "<BR" ) ) + "+****+<" + sTotalSubM.Substring( 
InBlock.gif            sTotalSubM.IndexOf( 
"<BR" ) + 3 );
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif                            
while( sTotalSubM.IndexOf( "<Br" ) >= 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                sTotalSubM 
= sTotalSubM.Substring( 
InBlock.gif            
0,sTotalSubM.IndexOf( "<Br" ) ) + "+****+<" + sTotalSubM.Substring( 
InBlock.gif            sTotalSubM.IndexOf( 
"<Br" ) + 3 );
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif                            
while( sTotalSubM.IndexOf( "<bR" ) >= 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                sTotalSubM 
= sTotalSubM.Substring( 
InBlock.gif            
0,sTotalSubM.IndexOf( "<bR" ) ) + "+****+<" + sTotalSubM.Substring( 
InBlock.gif            sTotalSubM.IndexOf( 
"<bR" ) + 3 );
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif             
InBlock.gif
InBlock.gif                            
//去除html标记
InBlock.gif

InBlock.gif                            
int linshiInt1 = sTotalSubM.IndexOf( "<" );
InBlock.gif
InBlock.gif                            
int linshiInt2 = sTotalSubM.IndexOf( ">" );          
InBlock.gif              
InBlock.gif
InBlock.gif             
InBlock.gif
InBlock.gif                            
if ( linshiInt2 < linshiInt1 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                sTotalSubM 
= sTotalSubM.Substring( linshiInt2 + 
InBlock.gif            
1 );
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif                            
int linshiInt11 = sTotalSubM.LastIndexOf( "<" );
InBlock.gif
InBlock.gif                            
int linshiInt12 = sTotalSubM.LastIndexOf( ">" );
InBlock.gif
InBlock.gif                            
if ( linshiInt12 < linshiInt11 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                sTotalSubM 
= sTotalSubM.Substring( 0,linshiInt12 
InBlock.gif            
+ 1 );
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif                            linshiInt1 
= sTotalSubM.IndexOf( "<" );
InBlock.gif
InBlock.gif                            
while ( linshiInt1 >= 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                linshiInt2 
= sTotalSubM.IndexOf( ">",linshiInt1 
InBlock.gif            );
InBlock.gif
InBlock.gif                                
if ( linshiInt2 >= 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{               
InBlock.gif
InBlock.gif                                    sTotalSubM 
= sTotalSubM.Substring( 
InBlock.gif            
0,linshiInt1 ) + sTotalSubM.Substring( linshiInt2 + 1 );
InBlock.gif
ExpandedSubBlockEnd.gif                                }

InBlock.gif
InBlock.gif                                
else
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{
InBlock.gif
InBlock.gif                                    sTotalSubM 
= sTotalSubM.Substring( 
InBlock.gif            
0,linshiInt1 );
InBlock.gif
ExpandedSubBlockEnd.gif                                }

InBlock.gif
InBlock.gif                                linshiInt1 
= sTotalSubM.IndexOf("<");
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif             
InBlock.gif
InBlock.gif                            
//还原关键标记
InBlock.gif

InBlock.gif                            
int linshiInt3 = 0;
InBlock.gif
InBlock.gif                            
int linshiInt4 = 0;
InBlock.gif
InBlock.gif             
InBlock.gif
InBlock.gif                            
while( sTotalSubM.IndexOf( "+****+" ) >= 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                sTotalSubM 
= sTotalSubM.Substring( 
InBlock.gif            
0,sTotalSubM.IndexOf( "+****+" ) ) + "<br>\n" + 
InBlock.gif            sTotalSubM.Substring( sTotalSubM.IndexOf( 
"+****+" ) + 9 );
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif                            
while( sTotalSubM.IndexOf( "|****|" ) >= 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                sTotalSubM 
= sTotalSubM.Substring( 
InBlock.gif            
0,sTotalSubM.IndexOf( "|****|" ) ) + "<br>\n" + 
InBlock.gif            sTotalSubM.Substring( sTotalSubM.IndexOf( 
"|****|" ) + 9 );
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif                            
while( sTotalSubM.IndexOf( "******" ) >= 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                linshiInt3 
= sTotalSubM.IndexOf( "******" ) + 9;
InBlock.gif
InBlock.gif                                linshiInt4 
= sTotalSubM.IndexOf( 
InBlock.gif            
"******",linshiInt3 );
InBlock.gif
InBlock.gif                                
if ( linshiInt4 >= 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{
InBlock.gif
InBlock.gif                                    
int tmpPos = sTotalSubM.IndexOf( "******" );
InBlock.gif
InBlock.gif                                    
string tmpStr1 = sTotalSubM.Substring( 
InBlock.gif            
0,tmpPos ); 
InBlock.gif
InBlock.gif                                    
string tmpStr2 = sTotalSubM.Substring( 
InBlock.gif            linshiInt3,linshiInt4 
- linshiInt3 );
InBlock.gif
InBlock.gif                                    
string tmpStr3 = sTotalSubM.Substring( 
InBlock.gif            linshiInt4 
+ 9 );
InBlock.gif
InBlock.gif                                    sTotalSubM 
= tmpStr1 + "<img src=" + tmpStr2 
InBlock.gif            
+ ">" + tmpStr3;
InBlock.gif
ExpandedSubBlockEnd.gif                                }

InBlock.gif
InBlock.gif                                
else
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{
InBlock.gif
InBlock.gif                                    
break;
InBlock.gif
ExpandedSubBlockEnd.gif                                }

InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif                            
//去除内容中的标题
InBlock.gif

InBlock.gif                            
if ( sTotalSubM.IndexOf( subTitle ) >= 0 )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                sTotalSubM 
= sTotalSubM.Substring( 
InBlock.gif            
0,sTotalSubM.IndexOf( subTitle ) ) + sTotalSubM.Substring( 
InBlock.gif            sTotalSubM.IndexOf( subTitle ) 
+ subTitle.Length );
InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
InBlock.gif                            reContentStr 
= sTotalSubM;
InBlock.gif
InBlock.gif                            
//调用下载图片功能
InBlock.gif
InBlock.gif                            
//下载图片到指定目录
InBlock.gif

InBlock.gif                            
string[] img_Url = new PublicFun().split( 
InBlock.gif            rePicStr,
"||" );
InBlock.gif
InBlock.gif                            
for ( int i=0;i<img_Url.Length;i++ )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                
if ( img_Url[i] != "" )
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                                
dot.gif{
InBlock.gif
InBlock.gif                                    
new PublicFun().Get_Img( 
InBlock.gif            img_Url[i],
10000,root + "\\images\\" + img_Url[i].Substring( 
InBlock.gif            img_Url[i].LastIndexOf(
"/")+1 ) );
InBlock.gif
ExpandedSubBlockEnd.gif                                }

InBlock.gif
ExpandedSubBlockEnd.gif                            }

InBlock.gif
ExpandedSubBlockEnd.gif                        }

InBlock.gif
InBlock.gif                        
return reContentStr;
InBlock.gif
ExpandedBlockEnd.gif                    }

None.gif
None.gif            以上方法返回要取得的信息,包括标题内容,图片地址等。
None.gif
None.gif             
None.gif
None.gif            下载页面中图片:
None.gif
None.gif            
// 下载图片
None.gif

None.gif                    
public   void  Get_Img( string  a_strUrl, int  timeout, string  
None.gif            filepath)
None.gif
ExpandedBlockStart.gifContractedBlock.gif                    
dot.gif {
InBlock.gif
InBlock.gif                        
try
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif
InBlock.gif            HttpWebRequest myReq 
= 
InBlock.gif            (HttpWebRequest)HttpWebRequest.Create(a_strUrl) ;
InBlock.gif
InBlock.gif                            myReq.Timeout 
= timeout;
InBlock.gif
InBlock.gif                            HttpWebResponse HttpWResp 
= 
InBlock.gif            (HttpWebResponse)myReq.GetResponse();         
InBlock.gif
InBlock.gif                            Stream myStream 
= HttpWResp.GetResponseStream () ;   
InBlock.gif                   
InBlock.gif
InBlock.gif                            Bitmap map 
= new Bitmap( myStream );
InBlock.gif
InBlock.gif                            PictureBox picB 
= new PictureBox();
InBlock.gif
InBlock.gif                            picB.Image 
= (Image)map;
InBlock.gif
InBlock.gif                            
string path = filepath.Substring( 
InBlock.gif            
0,filepath.LastIndexOf( "\\" ) );
InBlock.gif
InBlock.gif                            
if (!Directory.Exists(path))
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
dot.gif{
InBlock.gif
InBlock.gif                                CreateDir( path );
InBlock.gif
ExpandedSubBlockEnd.gif                            }
               
InBlock.gif
InBlock.gif                            picB.Image.Save(filepath);                
InBlock.gif
ExpandedSubBlockEnd.gif                        }

InBlock.gif
InBlock.gif                        
catch(Exception exp)
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif
InBlock.gif                            
string ss = exp.Message;
InBlock.gif
InBlock.gif                    WriteLog( filepath.Substring(
0,filepath.LastIndexOf("\\")) + 
InBlock.gif            
"\\error.log",a_strUrl + "--" + ss + "\r\n");        
InBlock.gif
ExpandedSubBlockEnd.gif                        }

InBlock.gif
ExpandedBlockEnd.gif                    }

None.gif
None.gif
None.gif            l         保存文件或入库
None.gif            上面取得的信息可以按自己的要求保存。
None.gif             
None.gif            
**** 设计的时候没有使用url按层次循环抓取,这样定义抓取url效率更高,速度更快。
None.gif

转载于:https://www.cnblogs.com/hzuIT/articles/897906.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值