Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Net;
  4.  
  5. namespace CrawlerPDN
  6. {
  7. class Core
  8. {
  9. class Cat
  10. {
  11. public String Name;
  12. public String url;
  13. }
  14.  
  15. public void Go(String url)
  16. {
  17. String contents = Download(url);
  18.  
  19.  
  20. int indexCat = contents.LastIndexOf("<LI type=square>");
  21.  
  22. Cat cat = new Cat();
  23. int indexUrlStart = contents.LastIndexOf("A href=\"", indexCat) + 1;
  24. int indexUrlLength = contents.IndexOf("\">") - indexUrlStart;
  25. int indexNameStart = contents.LastIndexOf("\">", indexUrlStart) + 1;
  26. int NameLength = contents.IndexOf("</A>") - indexNameStart;
  27. cat.url = contents.Substring(indexUrlStart, indexUrlLength);
  28. cat.Name = contents.Substring(indexNameStart, NameLength);
  29. }
  30.  
  31. private static string Download(string url)
  32. {
  33. string r = null;
  34. StreamReader strResponse = null;
  35. HttpWebResponse webResponse = null;
  36. try
  37. {
  38. var webRequest = (HttpWebRequest)WebRequest.Create(url);
  39. webResponse = (HttpWebResponse)webRequest.GetResponse();
  40. strResponse = new StreamReader(webResponse.GetResponseStream());
  41.  
  42. r = strResponse.ReadToEnd();
  43. }
  44. finally
  45. {
  46. if (strResponse != null) strResponse.Close();
  47. if (webResponse != null) webResponse.Close();
  48. }
  49. return r;
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement