Button click in web browser

后端 未结 2 1791
深忆病人
深忆病人 2021-01-14 09:22

I have created web browser, now i want to by clicking button1 on my form click the button on the web.

private void button1_Click(object sender, EventArgs e)
         


        
相关标签:
2条回答
  • 2021-01-14 10:14

    Try Iterating over all of the <input> elements in the webpage. When you find one with the value you want, you could click that element.

    foreach (HtmlElement el in webBrowser1.Document.GetElementsByTagName("input")
    {
        if (el.GetAttribute("value").Equals("→"))
        {
            el.InvokeMember("click");
        }
    }
    
    0 讨论(0)
  • 2021-01-14 10:17

    The website doesn't prevent POSTing a form to it. So you could always just create your own webpage with the form that points to it.

    HTML

    <form id="search" action="http://whois-service.ru/lookup/" method="post">
        <input type="text" class="text" name="domain" id="domain" />
        <input type="submit" value="" class="button" />
        <input id="submit" type="hidden" name="real" value="true2.1simpleJ" />
    </form>
    

    c#

    private void button1_Click(object sender, EventArgs e)
    {
        webBrowser1.DocumentText = "[The HTML from above here]";
        webBrowser1.Document.GetElementById("domain").SetAttribute("value", IP.Text);
        webBrowser1.Document.GetElementById("submit").InvokeMember("click");
    }
    

    If you are planning on scraping the WHOIS information. You must ensure it's not against the terms and conditions to do so. Most WHOIS services don't allow automated checks.

    If they do and that's what you are trying to do then you should consider using HttpWebRequest instead, it's much more efficient. See an example here on how to use http://swhobby.blogspot.co.uk/2010/03/c-example-of-http-post.html

    0 讨论(0)
提交回复
热议问题