好的,这是我的带有 ID 的 html 行:
<id="accounttype" class=inline-block"><strong><?=$_SESSION['accounttype']?></strong><br>
这就是它捕获的东西
当然,虽然这变成了文字
<?=$_SESSION['accounttype']?>
这是我的 vb.net 代码
TextBox4.Text = WebBrowser1.Document.GetElementById("accounttype").InnerText
当我运行程序时出现此错误
Object reference not set to an instance of an object.
最佳答案
我没有看到 ID 为 accounttype
的元素.我看到的只是一个 ID 为 newssite
的元素. GetElementById
返回具有属性 id
的元素等于你通过它的任何东西。例如:
<div id="accounttype">Hello World</div>
和 VB.NET 代码:
TextBox4.Text = WebBrowser1.Document.GetElementById("accounttype").InnerText
您可能没有包含代码;但是在尝试使用它之前,您还应该确保 WebBrowser 已完全加载其内容。
关于VB.NET GetElementById 内文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7027217/