C#获取替代HTML代码的span标签中的文本的文本 [英] C# Get text which replaces text from span tags of an HTML code

查看:118
本文介绍了C#获取替代HTML代码的span标签中的文本的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在C#中执行一个控制台应用程序,它从特定的网页中读取一些文本。现在我有一些问题,因为我不知道如何阅读标签之间的文本。
首先,我使用WebClient对象从网页下载html代码。

I have to do a console application in C# which reads some text from specific webpages. Now I have some problems because I dont know how to read text between tags. To begin with, I am downloading the html code from the webpage using WebClient object.

WebClient client = new WebClient();
String htmlCode = client.DownloadString(link);

htmlCode 字符串中,标记之间有一个图像,它是一个gif

In htmlCode string, between tags I have an image which is a gif of an loading bar.

<span id="bitrate_0"><img src="http://webpage.net/images/loading.gif" /></span>

如果我从浏览器访问该网站并检查该部分或使用Inspect Element功能其中显示我的HTML代码)在该网页的一部分,我有一个长文本(我需要得到)。
此外,在浏览器中,如果我选择查看源代码,仍然有这些代码。

If I go to that website from a browser and check that part or if I use Inspect Element feature (which shows me html code) on that part of the webpage, I have a long text (which I need to get). In addition, in the browser, if I choose to View source, there still are those tags.

我需要获取替换gif图像的文本。

I need to get the text which replaces the gif image. How can I do that?

谢谢。

推荐答案

Just所以你会很方便的:

Just so you'll have it handy:

  • Agility Pack - codeplex site
  • Html Agility Pack Test Bed - great tool if you're going to work with agility pack.
  • XPath tutorial on w3schools. You want to read this before you play with Agility.

上面已经说过了,如果你把时间花在上面材料,你不应该有找到跨度和玩弄它的问题。

Having said the above, if you put in the time to go through the above material, you shouldn't have a problem of finding the span and playing around with it.

祝你好运:)

这篇关于C#获取替代HTML代码的span标签中的文本的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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