Code to be used for crawler software development

Source: Internet
Author: User

1. Time stamp converted to C # format time

        /// <summary>        ///time stamp to C # format time/// </summary>        /// <param name= "TimeStamp" >UNIX timestamp format</param>        /// <returns>C # format time</returns>        PrivateDateTime GetTime (stringTimeStamp) {DateTime Dtstart= TimeZone.CurrentTimeZone.ToLocalTime (NewDateTime (1970,1,1)); LongLtime =Long. Parse (TimeStamp +"0000"); TimeSpan Tonow=NewTimeSpan (ltime); returnDtstart.add (Tonow); }

2. Get the Verification code

  PublicImage getimg (stringURL) {            if(string. Isnullorwhitespace (URL)) {URL=string. Format ("http://ms.baihe.com/checkcode/defaultImageService?0. {0}", DateTime.Now.Ticks); } Cookiecheckcode=""; varitem =NewHttpitem () {URL=URL,//Encoding = System.Text.Encoding.GetEncoding ("GBK"),Method ="Get",                //Istolower = False,Expect100continue =false,//agent, use this .Cookie =_cookie, Timeout=100000, Readwritetimeout=30000, useragent="mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) gecko/20100101 firefox/28.0", ContentType="text/html", Resulttype=Resulttype.byte}; varresult =http.            Gethtml (item); if(result.) Cookie! =NULL) Cookiecheckcode+ = result. Cookie.startswith ("Phpsessid")                    ? Result. Cookie.substring (result. Cookie.indexof (',') +1): result.            Cookies; returnbytearraytoimage (result.        Resultbyte); }        PrivateImage ByteArrayToImage (byte[] Bytes) {            using(varms =NewMemoryStream (Bytes)) {                returnBitmap.fromstream (MS,true); }        }

3. The regular table uses the class

Regex re =NewRegex (@"&uid= (\d+) \ "" Class=\ "" yellow\ "" > (. +) </a>", Regexoptions.none); MatchCollection MC=Re. Matches (resulthtml.            Html); varList =NewList<user>(); foreach(Match matchinchMC) {varUID = match. groups[1].                Value; varNick = match. groups[2].                Value; List. ADD (NewUser {uid = uid, nickname =Nick}); }

4. Get time

         Public Long Gettimelikejs ()        {            varnew DateTime (197011);             var t = (DateTime.Now.ToUniversalTime ()- st);             return (long) t.totalmilliseconds;        }

5. Another thread to operate the main thread of the control

           this. Invoke (Action)delegate()                    {                        this" login succeeded ";                    });

Code to be used for crawler software development

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.