0

我有我的 c# 浏览器,在我的程序中,当 URL 更改为某个值时,我希望程序单击链接列表中的特定链接。

这是链接的代码:

<table cellpadding="1" cellspacing="1">
  <tbody>       
    <td class="goTo" id="goToAdventure344183">
      <a class="gotoAdventure arrow" href="start_adventure.php?from=list&amp;kid=344183">إلى المغامرة</a>
    </td>
  </tbody>
</table>

类 id :"goToAdventure344183" 随时间更改为此 id "goToAdventure*******"

||| 只有星星变了|||

我想知道是否有办法实现它,如果你可以按类名或其他东西点击它,我在哪里,但 rbowser 或按钮中的代码或......

4

1 回答 1

0

如果 idgoToAdventure***总是为TD标签设置,你可以试试这个:(否则更改此代码:D)

public Form1()
        {
            InitializeComponent();
            webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            webBrowser1.DocumentText = "<html><body><table cellpadding=\"1\" cellspacing=\"1\"><tbody>     <td class=\"goTo\" id=\"goToAdventure344183\"><a class=\"gotoAdventure arrow\" href=\"start_adventure.php?from=list&amp;kid=344183\">إلى المغامرة</a></td> </tbody></table></body></html>";
        }

        void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            var s = webBrowser1.Document.Body.Children;
            foreach (var item in  webBrowser1.Document.GetElementsByTagName("td"))
            {
                //<TD> tag id contain goToAdventure
                if ((item as HtmlElement).Id.Contains("goToAdventure"))
                {
                    //Add <A> tag
                    foreach (var taga in (item as HtmlElement).GetElementsByTagName("a"))
                    {
                        webBrowser1.Navigate((taga as HtmlElement).GetAttribute("href"));
                        return;
                    }

                }
            }
        }
于 2013-09-25T18:00:38.630 回答