See how Tongliang Windows is the "one" that runs unattended

Source: Internet
Author: User

Tongliang window is I do a regional information site, but I have only one person, then how to let the information flow every day to collect in it?

Today I share with you is the way to get started: fixed-point acquisition News "development tool VS2012"

The acquisition of information must be a good way to collect a variety of Web pages without error, the following code can be copied directly using:

        private string Pushtoweb (string url, Encoding encode)  //Tongliang Windows www.5atl.com No collection        {            try            {                string Htmlstr = "";                if (! String.IsNullOrEmpty (URL))                {                    WebRequest request = webrequest.create (URL);            Instantiate the WebRequest object                    WebResponse response = Request. GetResponse ();           Create WebResponse object                    Stream datastream = response. GetResponseStream ();       Create stream object                    StreamReader reader = new StreamReader (datastream, encode);                    HTMLSTR = reader. ReadToEnd ();                           Read Data                    reader. Close ();                    DataStream. Close ();                    Response. Close ();                }                return htmlstr;            }            Catch            {                return "";            }        }

  

Some of the pages are plain text, the above method can be, but some pages are with pictures, and you do not want to make their own site is all other people's outside the chain, how to do? Follow these methods to solve your problem:

        public string getlocaltextimg (String page, string title)//Tongliang Windows www.5atl.com Unattended, image download to local {Strin            G regimg = "src=\" http: (? <url>[^\ "]*) \" ";            MatchCollection ms = Regex.Matches (page, regimg); if (ms = = NULL | | | Ms.            Count < 1) {return page; } foreach (Match m in ms) {string imgurl = "http:" + m.groups[1].                Value; String extend = Imgurl. Substring (Imgurl. LastIndexOf (".")).                ToLower ();                bool Needsave = true; if (Extend! = ". gif" && extend! = ". jpg" && extend! = ". png" && extend! = ". jpeg" && Exten                    D! = ". gif") {Needsave = false;                Extend = ". png";                } string dir = "/attachment/downimg/" + DateTime.Now.ToString ("yyyymm");                String sdir = Server.MapPath (dir); String guid = Guid.NewGuid (). ToSTring (); if (!                Directory.Exists (Sdir)) {directory.createdirectory (sdir);                } string path = Sdir + "/" + GUID + extend;                BOOL saved = filehelper.downwebimg (path, imgurl);                if (!saved) {continue;                } string savedurl = dir + "/" + GUID + extend; page = page.                Replace (Imgurl, Savedurl); try {if (needsave) {cms_albums alb = new CMS                        _albums (); Alb.                        Albumdescription = title; Alb.                        Albumname = title; Alb.                        Albumpic = Savedurl; Alb.                        Albumtype = ""; Alb.                        shopid = 0; Alb.                        KeyWords = title; Alb.                        Smallone = Savedurl; Alb.                       Picguid = GUID; Cms_albumsbasedal.create (ALB);        }} catch {}} return page; }

  

The above two methods is the foundation of the site operation, tomorrow will be released to see how Tongliang windows is unmanned operation of "one", the core technology of website operation, you may also, but perhaps you have not thought that can be used this way!

See how Tongliang Windows is the "one" that runs unattended

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.