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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14170701/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 11:47:00  来源:igfitidea点击:

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

vb.netvb.net-2010

提问by Sillygoose4u

How do I get a string from an HTML document using span ID in VB.NET (Visual Basic 2010)?

如何在 VB.NET (Visual Basic 2010) 中使用 span ID 从 HTML 文档中获取字符串?

I am working on a project, and I wanted to extract text from a webpage span to my application's textbox1.text. I only used this so far:

我正在做一个项目,我想从网页跨度中提取文本到我的应用程序的textbox1.text. 到目前为止我只使用过这个:

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

采纳答案by Sillygoose4u

You are using ...ByNameand not ...ByIDwhich mean you need to use the nameattribute of the spanelement:

您正在使用...ByNameand not...ByID这意味着您需要使用元素的name属性span

<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>