使用WebBrowser检查元素

时间:2015-01-29 04:43:34

标签: c# null element document inspect

我需要在winamax现场投注页面获得赔率。唯一的问题是HTML代码中不存在这些赔率。我必须右键单击奇数并单击“检查元素”。

问题是我必须使用C#来实现。 这是代码

WebBrowser webBrowser1 = new WebBrowser();
webBrowser1.Navigate("https://www.winamax.fr/paris-sportifs#/live");
StringBuilder sb2 = new StringBuilder();
foreach (HtmlElement elm in webBrowser1.Document.All)
    if (elm.GetAttribute("className") == "contestant-name")
        sb2.Append(elm.InnerHtml);
HtmlDocument doc = webBrowser1.Document;
doc.Body.InnerHtml = sb2.ToString();

当我编译它时,它向我显示webBrowser1.Document为null。没有这样的HtmlElement。

有人知道为什么webBrowser1.Document为空吗?

1 个答案:

答案 0 :(得分:-1)

所以,如果我理解,我必须在我的EventHandler中添加一个函数。 但是我要在之前或在我的EventHandler中启动我的导航吗?

我尝试了这个,但事件处理程序中需要一个方法名称。我真的不知道该怎么做。

public static void wina()
{            

    WebBrowser webBrowser1 = new WebBrowser();
    webBrowser1.Navigate("https://www.winamax.fr/paris-sportifs#/live");
    webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(recup(webBrowser1));


}

public static void tryrecup(WebBrowser e)
{

    StringBuilder sb2 = new StringBuilder();
    foreach (HtmlElement elm in e.Document.All)
        if (elm.GetAttribute("className") == "contestant-name")
            sb2.Append(elm.InnerHtml);
    HtmlDocument doc = e.Document;
    doc.Body.InnerHtml = sb2.ToString();
}