如何在C#windows窗体应用程序中获取Web标记文本 [英] How do I get web tags text in C# windows form application

查看:265
本文介绍了如何在C#windows窗体应用程序中获取Web标记文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用这个鳕鱼来获取网络标签文字

代码



I can use from this cod to get web tags text
code

private void button1_Click(object sender, EventArgs e)
    {
         HtmlDocument doc = this.webBrowser1.Document;

        textBox1.Text=doc.GetElementById("text id").GetAttribute("value");

    }





网址:





Web:

<input id="text id" value="123">







但是,我不能为这个网络标签做这个...



网址:






But, I cannot to do this for this web tags...

Web:

<input  value="123">





我尝试了什么:



i希望从网站上获取文本以使用文本我的Windows窗体应用程序



What I have tried:

i want to get text from a web site to use it text in my windows form application

推荐答案

你必须使用GetElementsByTagName方法:



You have to use GetElementsByTagName method for that like:

var inputs = doc.GetElementsByTagName("input");





它将返回一个集合,你必须在循环中迭代它以获取值:





it will return a collection, you have to iterate over it in a loop to get values:

foreach (HtmlElement input in inputs)
{
     
     var val = input.GetAttribute("value");
}


这篇关于如何在C#windows窗体应用程序中获取Web标记文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆