Reputation: 195
please use hpple(xpath), This is a followup to my previous question:
http://stackoverflow.com/questions/6723244/iphone-how-to-select-this-label
How can I get the number in seekVideo(number)
? For example:
<a href="#" class="transcriptLink" onclick="seekVideo(2000); return false;"
I want to get "2000".
I have tried:
NSArray *elements = [xpathParser search:@"//div[@id='transcriptText']/div/p/number(substring-before(substring-after(@onclick, '('), ')'))"];
But that's not right. How should i do this?
If someone can you use the code framework named hpple(xpath) , it would be great.
this is my code for get text ,now how to change for getting number?????
#define WebSite @"http://www.ted.com/talks/matt_cutts_try_something_new_for_30_days.html"
- (void)setLoadData
{
NSData *siteData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:WebSite]];
TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:siteData];
NSArray *elements = [xpathParser search:@"//div[@id='transcriptText']/div/p/a[number(substring-before(substring-after(@onclick, '('), ')')) >2000]/text()"];
NSMutableArray *arr = [[NSMutableArray alloc] init];
for (TFHppleElement *element in elements)
{
NSString *strs = [element content];
NSLog(@"cc: %@", strs);
[arr addObject:strs];
NSLog(@"arr: %@", arr);
}
self.listData = arr;
[arr release];
[xpathParser release];
}
Upvotes: 0
Views: 1157
Reputation: 243479
I have tried:
NSArray *elements = [xpathParser
search:@"//div[@id='transcriptText']/div/p/number(substring-before(substring-after(@onclick,
'('), ')'))"];
But that's not right. How should i do ?
In XPath 1.0 it is syntactically illegal to have a function call as a location step.
Try:
substring-before(substring-after(.../a/@onclick, 'seekVideo('),
')'
)
Or try:
number(
substring-before(substring-after(.../a/@onclick, 'seekVideo('),
')'
)
)
where ...
must be substituted with the XPath expression that selects the parent of a
.
Upvotes: 1