Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Net;
- namespace CrawlerPDN
- {
- class Core
- {
- class Cat
- {
- public String Name;
- public String url;
- }
- public void Go(String url)
- {
- String contents = Download(url);
- int indexCat = contents.LastIndexOf("<LI type=square>");
- Cat cat = new Cat();
- int indexUrlStart = contents.LastIndexOf("A href=\"", indexCat) + 1;
- int indexUrlLength = contents.IndexOf("\">") - indexUrlStart;
- int indexNameStart = contents.LastIndexOf("\">", indexUrlStart) + 1;
- int NameLength = contents.IndexOf("</A>") - indexNameStart;
- cat.url = contents.Substring(indexUrlStart, indexUrlLength);
- cat.Name = contents.Substring(indexNameStart, NameLength);
- }
- private static string Download(string url)
- {
- string r = null;
- StreamReader strResponse = null;
- HttpWebResponse webResponse = null;
- try
- {
- var webRequest = (HttpWebRequest)WebRequest.Create(url);
- webResponse = (HttpWebResponse)webRequest.GetResponse();
- strResponse = new StreamReader(webResponse.GetResponseStream());
- r = strResponse.ReadToEnd();
- }
- finally
- {
- if (strResponse != null) strResponse.Close();
- if (webResponse != null) webResponse.Close();
- }
- return r;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement