How to extract "meta[content$=.mp4]/content" from html document in ios?

134 Views Asked by At

I'm using hpple library for parsing HTML document.I want to extract .mp4 link and image link for video urls. Html tag looks like this:

<meta property="og:video" content="http://instagram.fbom1-1.fna.fbcdn.net/t50.2886-16/17686957_372561729804133_1618562720464896000_n.mp4">

code:

NSURL *instagramUrl = [NSURL URLWithString:@"https://www.instagram.com/p/BSdePkEFfO-/?tagged=video&hl=en"];
NSData *htmlData = [NSData dataWithContentsOfURL: instagramUrl];

TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];
NSArray *elements  = [xpathParser  searchWithXPathQuery:@"//div[@id='preview']"]; 
TFHppleElement *element = [elements objectAtIndex:0];
NSString *string = [element content];
NSLog(@"%@", string);

I'm getting TFHppleElement empty always.I have no idea about this someone, please help.

Thank you!

1

There are 1 best solutions below

0
sarita On

//to get .jpg link

 NSURL *cUrl = [NSURL URLWithString:url1];
    NSData *cHtmlData = [NSData dataWithContentsOfURL:cUrl];
    TFHpple *cParser = [TFHpple hppleWithHTMLData:cHtmlData];
    NSArray *elements = [cParser searchWithXPathQuery:@"//meta[@property='og:image']"];
    TFHppleElement *element = [elements objectAtIndex:0];
    NSDictionary *attributes = [element attributes];
    NSString *content1 = [attributes objectForKey:@"content"];

    NSLog(@"save instagram image content1=%@",content1);

//to get .mp4 link, use below xPathQuery

NSArray *elements = [cParser searchWithXPathQuery:@"//meta[@property='og:video']"];