I have html code like this
<html>
<head>
</head>
<body>
<a href='001'><img src='chp1.png'/></a>
<a href='002'><img src='chp2.png'/></a>
</body></html>
I want to get 001 or 002 in by use stringbyevaluatingjavascriptfromstring
like
[self.webView stringByEvaluatingJavaScriptFromString:@""];
have anyone know how to get it
Thx
I don't think -stringByEvaluatingJavaScriptFromString:
is a good choice here. Try using an NSScanner
:
NSScanner* scanner = [NSScanner scannerWithString:yourHTML];
while ([scanner scanUpToString:@"a href='" intoString:nil])
{
[scanner scanString:@"a href='" intoString:nil];
NSString* result = nil;
[scanner scanUpToString:@"'" intoString:&result];
//Do something with result, which will equal 001, then 002, etc.
}
Note that if you need to parse HTML you didn't write yourself, you'll need to add a lot more flexibility to this to account for possible stylistic differences (e.g. '
vs "
, href
vs HREF
).