Search code examples
iosobjective-cnsdata

NSData from dataWithContentsofURL has a specific key/value pair null


I'm attempting to parse some html off a specific site.

I grab all the content from the site and save it as NSData with this line.

NSData *testData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://somewebsite/"]];

I use TFHipple Scraper to go through every single element in the HTML, which works fine. I can see everything.

When I get to the specific element I'm looking it for, it has 5 key/value pairs as expected, verified with dev tools on the site. The scraper see's the first four and their correct values just fine.

Here's the problem, when it gets to the last key/value pair, "href" it's always null. This contains the link I'm trying to extract.

A colleague suggested that maybe some JS is injecting the link after the page loads, but I couldn't find anything to support that idea.

Any idea why "href" would be null but everything else is perfectly loaded?


Solution

  • The response data looks like JavaScript, not HTML. I don't think TFHipple will parse that. You could try using JavaScriptCore. NSHipster has a really good writeup on it.