Автоматическое нажатие как кнопки с C # - PullRequest
0 голосов
/ 25 декабря 2011

Моя цель состоит в том, чтобы нажимать на кнопки, похожие на Facebook, соответственно, но код не работает и не удалось выполнить оба действия.

    IEnumerator enumerator = null;
    IEnumerator enumerator2 = null;
    HtmlElementCollection all = this.WebBrowser1.Document.All;
    try {
        enumerator = all.GetEnumerator;
        while (enumerator.MoveNext()) {
            HtmlElement current = (HtmlElement)enumerator.Current;
            if ((current.GetAttribute("name") == "like")) {
                current.InvokeMember("click");
            }
        }
    } finally {
        if (enumerator is IDisposable) {
            (enumerator as IDisposable).Dispose();
        }
    }

код ошибки

Error 1 Cannot convert method group 'GetEnumerator' to non-delegate type 'System.Collections.IEnumerator'. Did you intend to invoke the method? C:\Users\S'rchade\AppData\Local\Temporary Projects\FriendFeeder\Form1.cs 37 30 FriendFeeder giving this

Ответы [ 2 ]

0 голосов
/ 25 декабря 2011

эта функция вернет все кнопки Like на странице, все остальное сделайте сами!

    static IEnumerable<HtmlElement> LikeButtons(HtmlDocument doc)
    {
        foreach (HtmlElement e in from HtmlElement e in doc.All where e.GetAttribute("className") == "default_message" &&  e.InnerText =="Like" select e)
            yield return e;
    }
0 голосов
/ 25 декабря 2011

Вы можете достичь этого

For Each abc As System.Windows.Forms.HtmlWindow In WebBrowser1.Document.Window.Frames
            For Each html As System.Windows.Forms.HtmlElement In WebBrowser1.Document.GetElementsByTagName("a")
                If html.InnerText = "" Then
                    html.InvokeMember("click")
                End If
            Next
Next
...