fork download
  1. using System;
  2. using System.IO;
  3. using System.Net;
  4. using System.Windows.Forms;
  5. using System.Diagnostics;
  6.  
  7. namespace ProxyBrowser
  8. {
  9. public class WebBrowserEx : WebBrowser
  10. {
  11. private string prevPage = null;
  12.  
  13. public WebBrowserEx(): base()
  14. {
  15. Initialize();
  16.  
  17. Document.Click += new HtmlElementEventHandler(Document_Click);
  18. }
  19.  
  20. private void Document_Click(object sender, HtmlElementEventArgs e)
  21. {
  22. string text = null;
  23. string link = null;
  24.  
  25. HtmlElement element = this.Document.GetElementFromPoint(e.MousePosition);
  26.  
  27. if (element.TagName == "a" || element.TagName == "A")
  28. {
  29. text = element.OuterText;
  30. link = element.GetAttribute("href");
  31. }
  32. else if (element.Parent != null)
  33. {
  34. text = element.Parent.OuterText;
  35. link = element.Parent.GetAttribute("href");
  36. }
  37.  
  38. if (link != null && link != "")
  39. {
  40. try
  41. {
  42. MessageBox.Show(text + "\n" + link);
  43. e.ReturnValue = false;
  44. }
  45. catch
  46. {
  47. }
  48. }
  49. }
  50.  
  51. private void Initialize()
  52. {
  53. UserAgent = null;
  54. Proxy = null;
  55. Cookie = null;
  56. Timeout = 5000;
  57.  
  58. }
  59.  
  60. public new void Navigate(string url)
  61. {
  62. string buffer = null; // バッファ
  63.  
  64. HttpWebRequest req = null;
  65. HttpWebResponse res = null;
  66.  
  67. #region リクエストの作成
  68. try
  69. {
  70. /* リクエストの設定 */
  71. req = (HttpWebRequest)WebRequest.Create(url);
  72.  
  73. // UserAgent
  74. if (this.UserAgent != null)
  75. req.UserAgent = UserAgent;
  76. // Proxy
  77. if(this.Proxy != null)
  78. req.Proxy = new WebProxy(this.Proxy);
  79. // Cookie
  80. if (this.Cookie != null)
  81. {
  82. req.CookieContainer = new CookieContainer();
  83. req.CookieContainer.Add(this.Cookie);
  84. }
  85. // Timeout
  86. if (this.Timeout != 5000)
  87. req.Timeout = this.Timeout;
  88.  
  89. }
  90. catch (UriFormatException e)
  91. {
  92. Debug.WriteLine(e.ToString());
  93. return;
  94. }
  95. catch (NotSupportedException e)
  96. {
  97. Debug.WriteLine(e.ToString());
  98. return;
  99. }
  100. catch (ArgumentException e)
  101. {
  102. Debug.WriteLine(e.ToString());
  103. return;
  104. }
  105. catch (System.Security.SecurityException e)
  106. {
  107. Debug.WriteLine(e.ToString());
  108. return;
  109. }
  110. #endregion
  111.  
  112. try
  113. {
  114. res = (HttpWebResponse)req.GetResponse();
  115.  
  116. Stream st = res.GetResponseStream();
  117.  
  118. using (StreamReader sr = new StreamReader(st))
  119. buffer = sr.ReadToEnd();
  120.  
  121. st.Close();
  122. }
  123. catch (WebException e)
  124. {
  125. Debug.WriteLine(e);
  126. return;
  127. }
  128. catch (ProtocolViolationException e)
  129. {
  130. Debug.WriteLine(e);
  131. return;
  132. }
  133. catch (InvalidOperationException e)
  134. {
  135. Debug.WriteLine(e);
  136. return;
  137. }
  138. }
  139.  
  140. public string UserAgent
  141. { get; set; }
  142.  
  143. public string Proxy
  144. { get; set; }
  145.  
  146. public CookieCollection Cookie
  147. { get; set; }
  148.  
  149. public int Timeout
  150. { get; set; }
  151. }
  152. }
  153.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty