2019/7/2
C#.net 用webbrowser類別自動抓取網頁程式
用webbrowser類別自動抓取網頁程式
protected void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox1.Text == "https://")
{
textBox1.Text = "https://qos.cht.com.tw";
}
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
Navigate(textBox1.Text);
/// 確認網頁是否讀取完畢的方法
private bool checkComplete(string keyword)
{
bool b = false;
while (!b)
{
if (webBrowser1.Document != null)
{
foreach (HtmlElement he in webBrowser1.Document.All)
{
//if(he.Id.Contains(keyword) )
if (he.Id == keyword)
//if (he.OuterText == keyword)
{
b = true;
}
}
}
Application.DoEvents();
}
return b;
}
private bool checkComplete2(string keyword)
{
bool b = false;
while (!b)
{
if (webBrowser1.Document != null)
{
foreach (HtmlElement he in webBrowser1.Document.All)
{
//MessageBox.Show("]" + he.OuterHtml + "[");
if(he.OuterHtml.Contains(keyword) )
//if (he.OuterHtml == keyword)
//if (he.OuterText == keyword)
{
b = true;
}
}
}
Application.DoEvents();
}
return b;
}
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言