C# Get text which replaces text from span tags of an HTML code

烂漫一生 提交于 2019-12-25 03:54:28

问题


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

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>

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.

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

Thank you.


回答1:


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.

Good luck :)



来源:https://stackoverflow.com/questions/25528126/c-sharp-get-text-which-replaces-text-from-span-tags-of-an-html-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!