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