Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Net;
  7. using System.IO;
  8. using HtmlAgilityPack;
  9.  
  10. namespace ConsoleApplication1
  11. {
  12. class Program
  13. {
  14. static void Main(string[] args)
  15. {
  16. string sURL;
  17. sURL = "http://personer.eniro.se/resultat/Daniel Forslund Stockholm";
  18. WebRequest wrGETURL;
  19. wrGETURL = WebRequest.Create(sURL);
  20. Stream objStream;
  21. objStream = wrGETURL.GetResponse().GetResponseStream();
  22. StreamReader objReader = new StreamReader(objStream);
  23.  
  24. string sLine = "";
  25. int i = 0;
  26. string full = "";
  27. while (sLine != null)
  28. {
  29. i++;
  30. sLine = objReader.ReadLine();
  31. if (sLine != null)
  32. full += sLine + Environment.NewLine;
  33. }
  34. HtmlDocument htmlDoc = new HtmlDocument();
  35. htmlDoc.LoadHtml(full);
  36.  
  37. HtmlNode address = htmlDoc.DocumentNode.SelectSingleNode("//address");
  38. string streetAddress = htmlDoc.DocumentNode.SelectSingleNode("//span[@class='hit-street-address']").InnerText.Trim();
  39. string postalCode = htmlDoc.DocumentNode.SelectSingleNode("//span[@class='hit-postal-code']").InnerText.Trim();
  40. string addressLocality = htmlDoc.DocumentNode.SelectSingleNode("//span[@class='hit-address-locality']").InnerText.Trim();
  41. Console.WriteLine(streetAddress + " " + postalCode + " " + addressLocality);
  42.  
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement