我遇到了问题,我不知道它的来源。这与点击ID
按钮有关。有人能解释我发生了什么事吗?
这应该比较来自客户端的消息,如果该消息是NxEpisode
,它将点击该按钮,但由于某种原因它不起作用。
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>
答案 0 :(得分: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");
}
}