I have the following HTML code:
2
<
If your HTML consists solely of that one tag, then this should do it:
String href = selenium.getAttribute("css=a@href");
You use the DefaultSelenium#getAttribute() method and pass in a CSS locator, an @ symbol, and the name of the attribute you want to fetch. In this case, you select the a and get its @href.
In response to your comment/edit:
The part after @ tells Selenium that that part is the name of the attribute.
You should place :contains('2') before @href because it's part of the locator, not the attribute. So, like this:
selenium.getAttribute("css=a:contains('2')@href");