Hello I am trying to find links in a NSString that has html in it. I am working on a web crawler and I'll need to find all links so that I can add it to my database.
I've tried to use RegexKit, but it didn't seem to work at all for me.
I know how to do this in php using preg_match_all
Thanks for any help.
I've tried to use RegexKit, but it didn't seem to work at all for me.
I know how to do this in php using preg_match_all
Code:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://example.com/");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_5_5; en-us) AppleWebKit/528.5+ (KHTML, like Gecko) Version/4.0dp1 Safari/526.11.2");
$result = curl_exec($ch);
curl_close($ch);
$links = array();
preg_match_all("/<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>.*<\/a>/siU", $result, $links);
print_r($links);
?>
Thanks for any help.