This commit is contained in:
2014-11-10 04:39:44 +00:00
parent 95bad8bf10
commit a03713e730
3 changed files with 66 additions and 0 deletions

13
Form1.Designer.cs generated
View File

@@ -37,6 +37,7 @@
this.lbRespCnt = new System.Windows.Forms.Label();
this.lbStatus = new System.Windows.Forms.Label();
this.btOpen = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// Process
@@ -102,11 +103,22 @@
this.btOpen.UseVisualStyleBackColor = true;
this.btOpen.Click += new System.EventHandler(this.btOpen_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(208, 128);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 6;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(367, 212);
this.Controls.Add(this.button1);
this.Controls.Add(this.btOpen);
this.Controls.Add(this.lbStatus);
this.Controls.Add(this.lbRespCnt);
@@ -134,6 +146,7 @@
private System.Windows.Forms.Label lbRespCnt;
private System.Windows.Forms.Label lbStatus;
private System.Windows.Forms.Button btOpen;
private System.Windows.Forms.Button button1;
}
}

View File

@@ -8,6 +8,7 @@ using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
using System.Net;
namespace WebChecker
{
@@ -27,6 +28,8 @@ namespace WebChecker
StreamWriter m_FileLog = new StreamWriter("WebChecker.log", true);
WebClient client = new WebClient();
public Form1()
{
InitializeComponent();
@@ -41,6 +44,9 @@ namespace WebChecker
wb.ScriptErrorsSuppressed = true;
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
client.DownloadDataCompleted +=new DownloadDataCompletedEventHandler(client_DownloadDataCompleted);
Log("=== App Launch ===");
}
@@ -93,6 +99,8 @@ namespace WebChecker
HtmlDocument doc = wb.Document;
HtmlElement element = doc.GetElementById("sbPersonalInfo");
if(element == null)
return;
element = element.Children[element.Children.Count-1];
element = element.Children[0];
element = element.GetElementsByTagName("IMG")[0];
@@ -198,5 +206,46 @@ namespace WebChecker
MessageBox.Show(other.Message);
}
}
private void button1_Click(object sender, EventArgs e)
{
//url = "http://main.com";
url = tbURL.Text;
client.DownloadDataAsync(new Uri(url));
}
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
}
void client_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
{
string conType = client.ResponseHeaders["Content-Type"];
int iPos = conType.IndexOf("charset");
Encoding enc = Encoding.Default;
if(iPos >= 0)
{
iPos = conType.IndexOf("=", iPos+"charset".Length);
if(iPos >= 0)
{
string charset = conType.Substring(iPos+1);
enc = Encoding.GetEncoding(charset);
}
}
string contents = enc.GetString(e.Result);
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(contents);
HtmlAgilityPack.HtmlNode node = doc.DocumentNode.SelectSingleNode("//ul[@class='info']/li/img");
HtmlAgilityPack.HtmlAttribute attr = node.Attributes["src"];
string strInnerText = "";
if(attr != null)
strInnerText = attr.Value;
}
}
}

View File

@@ -32,6 +32,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="HtmlAgilityPack, Version=1.4.6.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>.\HtmlAgilityPack.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>