Since you say the HTML is actually well-formed XHTML, then you can use any XML parsing method to parse the document and find what you are looking for. Using NSXMLParser and a valid parser delegate, you probably would have something like:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
if ([elementName isEqualToString:@"a"] && [[attributeDict objectForKey:@"id"] isEqualToString:@"logoutLink"]) {
// Found the <a> tag with an id of logoutLink
NSString *linkURL = [attributeDict objectForKey:@"href"];
// Do what you want with the link URL here
}
This assumes you are looking for a specific <a>
element with an id of logoutLink
. If you are looking for other ways to identify which <a>
tag has the URL you want you can adjust the if
statement in this sample code accordingly.