我正在尝试抓取 a website得到Textarea
信息。
我正在使用:
HtmlDocument doc = this.webBrowser1.Document;
当我查看 View 源时,它显示 <textarea name="message" class="profile">
但是当我尝试访问这个文本区域时:
HtmlDocument doc = this.webBrowser1.Document;
doc.GetElementsByTagName("textarea")
.GetElementsByName("message")[0]
.SetAttribute("value", "Hello");
显示错误:
Value of '0' is not valid for 'index'. 'index' should be between 0 and -1.
Parameter name: index
有什么帮助吗?
最佳答案
对于您当前的需要,您可以简单地使用它:
doc.GetElementsByTagName("textarea")[0].InnerText = "Hello";
对于复杂的事情,您可以将 HtmlDocument 类与 MSHTML 类一起使用。
关于c# - 通过 C# Web 浏览器抓取网站以获取元素名称和 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16222296/