如何使用C#访问特定的HTML元素? [英] How do I access a specific HTML element using C#?

查看:84
本文介绍了如何使用C#访问特定的HTML元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含HTML的字符串,我需要能够访问一个特定的元素来获取它的文本(该元素没有id或类或名称,因此正则表达式是不成问题的)。



例如,让我说我需要访问:/ html / body / div / div [3] / div / table [0] / div / ul / li [12] / a /。



我如何去做这个?

解决方案

HTML格式良好,您可以使用 XmlDocument



此外,Maxim提到, HTML Agility Pack < a>可以做你所需要的。



以下是4guysfromrolla的最新文章,使用HTML Agility Pack解析HTML


I have a string containing HTML and I need to be able to access a specific element to get the text from it (the element has no id or class or name so regex is out of the question).

For example, lets say I needed to access: "/html/body/div/div[3]/div/table[0]/div/ul/li[12]/a/".

How could I go about doing this?

解决方案

If the HTML is well formatted, you can parse the HTML with an XmlDocument

Also as Maxim mentioned, the HTML Agility Pack can probably do what you need.

Here's a recent article from 4guysfromrolla on parsing HTML with the HTML Agility Pack

这篇关于如何使用C#访问特定的HTML元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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