0

我有一个问题,我不知道它来自哪里。这与单击他的按钮有关ID。有人可以解释一下发生了什么吗?这应该比较来自客户端的消息,如果该消息是NxEpisode,它将单击该按钮,但由于某种原因它不起作用。

图片:http : //imgur.com/8DHqByV

C# 代码

    namespace WindowsFormsApplication2
{


public partial class Form1 : Form
{
    public Form1()
    {

        InitializeComponent();
        webBrowser1.Navigate("http://kissanime.com/Anime/One-Piece/Episode-692");

        System.Threading.Thread newThread = new System.Threading.Thread(serverfunction);
        newThread.Start();


    }
    private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {

    }


   public void serverfunction()
        {
            int port = 80;
            IPAddress localAddr = IPAddress.Parse("192.168.1.68");
            TcpListener server = new TcpListener(localAddr, port);

            server.Start();


            byte[] bytes = new byte[2048];
            string data;


            while (true)
            {
                TcpClient client = server.AcceptTcpClient();
                NetworkStream stream = client.GetStream();
                int i;
                i = stream.Read(bytes, 0, bytes.Length);
                data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
                Global.message = StripExtended(data);
                if (Global.message == "NxEpisode")
                {
                                        webBrowser1.Document.GetElementById("btnNext").InvokeMember("Click");
                }

                }

        }

    static string StripExtended(string arg)
    {
        StringBuilder buffer = new StringBuilder(arg.Length); //Max length
        foreach (char ch in arg)
        {
            UInt16 num = Convert.ToUInt16(ch);//In .NET, chars are UTF-16
            //The basic characters have the same code points as ASCII, and the extended characters are bigger
            if ((num >= 32u) && (num <= 126u)) buffer.Append(ch);
        }
        return buffer.ToString();
    }





}


    public class Global
    {
        public static string message = "";

    } 





}

html代码

    <a href="http://kissanime.com/Anime/One-Piece/Episode-692?id=108094">
<img id='btnNext' src="http://kissanime.com/Content/images/next.png" title="Next episode" border="0"/></a>
4

1 回答 1

0

我真的不知道是什么原因导致它无法正常工作,但试试这个:

<img id='btnNext' name='btnNext' src="http://kissanime.com/Content/images/next.png" title="Next episode" border="0"/></a>

如果它不起作用,也试试这个

foreach (HtmlElement el in webBrowser1.Document.GetElementsByTagName("img"))
            {
                if (el.Name == "btnNext")
                {
                    el.InvokeMember("Click");
                }
            }
于 2015-05-18T01:53:08.637 回答