Private Void Check (){ Int Currentnum = Currentnum; If (Currentnum> = Totalcount ){ Return ;} Datagridviewrow row = This . Maid [currentnum]; row. cells [ " ID " ]. Style. backcolor = Color. Green; String Url = row. cells [ " URL " ]. Value. tostring (); String Title = row. cells [ " Title " ]. Value. tostring (); Title = System. Web. httputility. htmlencode (title); WebClient Client =New WebClient (); client. Encoding = Encoding. utf8; Uri URI = New Uri (URL); system. Io. Stream stream = Null ;; Try {Stream = Client. openread (URI );} Catch (System. net. webexception ex ){ If (EX. Status = Webexceptionstatus. protocolerror) Row. defaultcellstyle. backcolor = Color. Yellow; If (EX. Status = Webexceptionstatus. connectfailure) Row. defaultcellstyle. backcolor = Color. Yellow; If (EX. Status = Webexceptionstatus. Timeout) Row. defaultcellstyle. backcolor = Color. Yellow; If (Stream! = Null ) Stream. Dispose (); client. Dispose (); Return ;} Using (System. Io. memorystream MS = New System. Io. memorystream ()){ Int Len = 0 ; Byte [] Buff = New Byte [ 512 ]; While (LEN = stream. Read (buff, 0 , 512 )> 0 ) {Ms. Write (buff, 0 , Len );} String Content = System. Text. encoding. utf8.getstring (Ms. toarray (); match charsetmatch = RegEx. Match (content, " <Meta ([^ <] *) charset = \"? '? ([^ <] *) \" " , Regexoptions. ignorecase | Regexoptions. multiline ); String Encoding = charsetmatch. Groups [ 2 ]. Value; If ( String . Isnullorempty (encoding) {Encoding = Client. responseheaders [httpresponseheader. contentencoding];} If (!String . Isnullorempty (encoding) & encoding. tolower ()! = " UTF-8 " ){ If (Encoding. tolower (). Contains ( " Gzip " )){ Using (System. Io. memorystream memory = New System. Io. memorystream () {Ms. Position = 0l ; Using (Gzipstream = New Gzipstream (MS, compressionmode. Decompress )){ While (LEN = gzipstream. Read (buff, 0 , 512 )> 0 ) {Memory. Write (buff, 0 , Len) ;}} content = System. Text. encoding. utf8.getstring (memory. toarray ());}} Else { Try { If (Encoding. tolower (). Contains ( " GBK " ) Encoding = " Gb2312 " ; Content = System. Text. encoding. getencoding (encoding). getstring (Ms. toarray ());} Catch {}} Match = Titleregex. Match (content ); If (! Match. Success) {row. defaultcellstyle. backcolor = Color. fromargb ( 255 , 200 , 200 , 200 );} Else If (Content. indexof (title) < 0 ) {Row. defaultcellstyle. backcolor = Color. fromargb ( 255 , 200 , 200 , 200 );}} If (Stream! = Null ) Stream. Dispose (); row. cells [ " ID " ]. Style. backcolor = color. fromargb ( 255 , 108 , 226 ,108 );}
Recently, we need to check the work of The promotion staff. If there are more than 500 external links per day, the manual check is really not harmonious. Write a checkProgram, Under backup.