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

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;
}
}
}