killah Posted June 15, 2009 Share Posted June 15, 2009 I am currently stuck on a solution. Let me explain, i have built a script which will take my test site & register the account, after that it then log's the account in. After the account has logged in. I need it to send it to another script.. Ok i got the script working to this part. The script basicly work's like this. Post form data -> register.php -> login.php -> mailbox.php?action=send so far that work's and send's the mail. My problem stand's that the user were sending to, can be anything. This is why i have came here. I need my curl script to send to usersonline.php and get a name inbetween a url link (<a href='viewuser.php?u=xx'>YY</a> xx => id, YY => name), i need to grab YY and put it in an array, so i can use it later on. Is there anyway to grab a name inbetween a html tag using cURL? I have the rest covered by going to usersonline.php and all. Thank's. Quote Link to comment Share on other sites More sharing options...
jxrd Posted June 15, 2009 Share Posted June 15, 2009 You could use DOM to do it. Or regex...but apparently that's less reliable. Quote Link to comment Share on other sites More sharing options...
killah Posted June 15, 2009 Author Share Posted June 15, 2009 Care to post an example? Quote Link to comment Share on other sites More sharing options...
jxrd Posted June 15, 2009 Share Posted June 15, 2009 Idk much about DOM, I've only heard it's the better option. Regex would probably be something like this preg_match($curl_return, '/<a href=\'viewuser\.php?u=[a-z]\'>([a-z])<\/a>/isS', $matches); print_r($matches); Quote Link to comment Share on other sites More sharing options...
killah Posted June 15, 2009 Author Share Posted June 15, 2009 Returns empty: Array ( ) Quote Link to comment Share on other sites More sharing options...
jxrd Posted June 15, 2009 Share Posted June 15, 2009 Crap, I'm thinking of strstr() syntax preg_match('/<a href=\'viewuser\.php?u=[a-z]\'>([a-z])<\/a>/isS', $curl_return, $matches); print_r($matches); Replace $curl_return with the curl return btw. Quote Link to comment Share on other sites More sharing options...
killah Posted June 15, 2009 Author Share Posted June 15, 2009 This is what i got: $mat = htmlentities(curl_exec($log)); preg_match('~<a href=\'viewuser.php?u=(.?)\'>(.?)</a>~isS', $mat, $matches); print_r($matches); except it doesnt pick up the \'viewuser.php?u=xx\' if i change my pattern to '~<a>' it picks up every link on the site. Quote Link to comment Share on other sites More sharing options...
jxrd Posted June 15, 2009 Share Posted June 15, 2009 Try changing (.?) to (.*?) Quote Link to comment Share on other sites More sharing options...
killah Posted June 15, 2009 Author Share Posted June 15, 2009 Nope. Quote Link to comment Share on other sites More sharing options...
jxrd Posted June 15, 2009 Share Posted June 15, 2009 This worked for me <?php $curl_return = '<a href=\'viewuser.php?u=something\'>username</a>'; preg_match('/<a href=\'viewuser\.php\?u=[a-z]+\'>([a-z]+)<\/a>/isS', $curl_return, $matches); print_r($matches); Quote Link to comment Share on other sites More sharing options...
killah Posted June 15, 2009 Author Share Posted June 15, 2009 Ok, let me explain this bit. Basicly it log's into a full layout site, thus is why im using htmlentities/htmlspecialchars.. I need to search then for <a href='viewuser.php?u=[0-9]'>[a-z0-9 _-!]</a> Hope you can maybe figure a solution to that Quote Link to comment Share on other sites More sharing options...
killah Posted June 15, 2009 Author Share Posted June 15, 2009 Here's an update. curl_setopt($log, CURLOPT_URL, $url.'/usersonline.php'); $mat = str_replace(array('<','>'),array('[',']'), curl_exec($log)); echo $mat; $mat = preg_replace('~\[a href=\'viewuser.php?u=(.*)\'\](.*)\[/a\]~is','[pid]$2[/pid]', $mat); preg_match('~\[pid\](.*)\[/pid\]~is', $mat, $matches); print_r($matches); It displays: [a href=viewuser.php?u=2]Kyle[/a] But it simply won't grab the bit inside ]YY[ I just noticed your using preg_match when it's supposed to be preg_match_all, but now my array returns: Array ( [0] => Array ( ) [1] => Array ( ) ) Quote Link to comment Share on other sites More sharing options...
jxrd Posted June 15, 2009 Share Posted June 15, 2009 <?php $curl_return = '<a href=\'viewuser.php?u=something\'>username</a>'; $curl_return = str_replace(array('<', '>'), array('[', ']'), $curl_return); preg_match('/\[a href=\'viewuser\.php\?u=[a-z]+\'\]([a-z]+)\[\/a\]/i', $curl_return, $matches); print_r($matches); Come on..surely you can adapt this. Quote Link to comment Share on other sites More sharing options...
killah Posted June 15, 2009 Author Share Posted June 15, 2009 Your example work's perfect, it just doesnt work with my script for some reason :S Quote Link to comment Share on other sites More sharing options...
jxrd Posted June 15, 2009 Share Posted June 15, 2009 What's the url of the page you are trying to scrape? Quote Link to comment Share on other sites More sharing options...
killah Posted June 15, 2009 Author Share Posted June 15, 2009 I PM'ed it to you. Recheck the link if you got the disabled bit's. Quote Link to comment Share on other sites More sharing options...
jxrd Posted June 15, 2009 Share Posted June 15, 2009 This script is to powerful for you. Your ip is not in the wanted list, your unwanted fool! Current IP: 82.28 Lol. Quote Link to comment Share on other sites More sharing options...
killah Posted June 15, 2009 Author Share Posted June 15, 2009 Reload the page, as i just marked that out.. Quote Link to comment Share on other sites More sharing options...
killah Posted June 16, 2009 Author Share Posted June 16, 2009 Bump Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.