0

I'm working with an api that requires a key only found when doing an Http GET request from the initial web page. So in my app I do a simple GET request and get back the xhtml. I'm looking for advice about how to pull a specific value from a javascript assignment statement found in this response.

<html>
 <body>
  <div>
  </div>
  <script type="text/javascript">abc.123.key = 'Ikc8StJJiJ2Pq/Dl+iUz3MFzk6qnL7mz6hFFkn5LtZM=';</script>
 </body>
</html>

In the example above I'm looking to capture the value "Ikc8StJJiJ2Pq/Dl+iUz3MFzk6qnL7mz6hFFkn5LtZM=" from the assignment of abc.123.key. Should I do a simple regex and if so what would a simple example look like to get me started?

2 Answers 2

2

If you are loading this xhtml into an UIWebView you can do the following

NSString* key = [myWebView stringByEvaluatingJavaScriptFromString:@"abc.123.key"];
Sign up to request clarification or add additional context in comments.

Comments

1

You can drill down using XPath to get to the script tag, with an expression like /html/body/script/text(), and then use a simple regex to get the key you want.

1 Comment

Any way I could get a little more detail on this solution in pure XPath? The typical google search isn't returning much of value for a simple example like this (library free that is).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.