-1

I have a requirement where i need to get the value of a span element from HTML web page source. I am able to get the entire HTML page source but i could not be able to retrieve the value inside the following span element

<span id="MySpanID"> This is my span</span>

I have used componentsSeperatedByString in order to split the HTML page source string into array elements based on span element as shown in the code line below.

NSArray *arrayComponents = [htmlPageSourceString componentsSeparatedByString:@"<span id="MySpanID">"];

The above line of code is always returning nil value due to which i could not able to split the string into array and retrieve the value present inside the span element . Can you please suggest any solution to retrieve the span element value from HTML Web page source?

zx8754
  • 52,746
  • 12
  • 114
  • 209
Kamal
  • 453
  • 1
  • 10
  • 22

1 Answers1

0

Not sure how you're able to run this line of code

NSArray *arrayComponents = [htmlPageSourceString componentsSeparatedByString:@"<span id="MySpanID">"];

Because quotes inside NSString should be escaped with \.

Try to use

NSArray *arrayComponents = [htmlPageSourceString componentsSeparatedByString:@"<span id=\"MySpanID\">"];

It should work.

testdrive
  • 41
  • 6