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