1

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?

4
  • 1
    What do the numbers inside the brackets mean? Commented Feb 19, 2011 at 4:55
  • I think Html Agility Pack has something for that. Commented Feb 19, 2011 at 4:55
  • @RobertHarvey: I'm guessing that div[3] means the 3rd div contained in that parent div, and so on. Commented Feb 19, 2011 at 4:56
  • @Robert Harvey: I assume you have never used firebug? When there are multiple tags of the same type at the same depth, the number is the index of occurance of that tag. Commented Feb 19, 2011 at 4:58

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.