简体   繁体   English

如何在VB.NET(Visual Basic 2010)中使用跨度ID从HTML获取文本?

[英]How to get a text from HTML using span ID in VB.NET (Visual Basic 2010)?

How do I get a string from an HTML document using span ID in VB.NET (Visual Basic 2010)? 如何在VB.NET(Visual Basic 2010)中使用跨度ID从HTML文档中获取字符串?

I am working on a project, and I wanted to extract text from a webpage span to my application's textbox1.text . 我正在做一个项目,我想从网页范围中提取文本到应用程序的textbox1.text I only used this so far: 到目前为止,我只使用了此方法:

TextBox1.Text = WebBrowser1.Document.All.GetElementsByName("***I put the span id here, but it didn't work.***")(0).InnerText

You are using ...ByName and not ...ByID which mean you need to use the name attribute of the span element: 您正在使用...ByName而不是...ByID ,这意味着您需要使用span元素的name属性:

<span name="myName">...</span>

To use ID instead of name try replacing your code to (untested): 要使用ID代替名称,请尝试将代码替换为(未试用):

TextBox1.Text = _
 WebBrowser1.Document.GetElementById("spanID").GetAttribute("innerText")

... ...

<span id="spanID">...</span>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM