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. Link to comment https://forums.phpfreaks.com/topic/162242-curl-help/ 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. Link to comment https://forums.phpfreaks.com/topic/162242-curl-help/#findComment-856242 Share on other sites More sharing options...
killah Posted June 15, 2009 Author Share Posted June 15, 2009 Care to post an example? Link to comment https://forums.phpfreaks.com/topic/162242-curl-help/#findComment-856246 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); Link to comment https://forums.phpfreaks.com/topic/162242-curl-help/#findComment-856253 Share on other sites More sharing options...
killah Posted June 15, 2009 Author Share Posted June 15, 2009 Returns empty: Array ( ) Link to comment https://forums.phpfreaks.com/topic/162242-curl-help/#findComment-856269 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. Link to comment https://forums.phpfreaks.com/topic/162242-curl-help/#findComment-856270 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. Link to comment https://forums.phpfreaks.com/topic/162242-curl-help/#findComment-856276 Share on other sites More sharing options...
jxrd Posted June 15, 2009 Share Posted June 15, 2009 Try changing (.?) to (.*?) Link to comment https://forums.phpfreaks.com/topic/162242-curl-help/#findComment-856280 Share on other sites More sharing options...
killah Posted June 15, 2009 Author Share Posted June 15, 2009 Nope. Link to comment https://forums.phpfreaks.com/topic/162242-curl-help/#findComment-856286 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); Link to comment https://forums.phpfreaks.com/topic/162242-curl-help/#findComment-856288 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 Link to comment https://forums.phpfreaks.com/topic/162242-curl-help/#findComment-856294 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 ( ) ) Link to comment https://forums.phpfreaks.com/topic/162242-curl-help/#findComment-856301 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. Link to comment https://forums.phpfreaks.com/topic/162242-curl-help/#findComment-856304 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 Link to comment https://forums.phpfreaks.com/topic/162242-curl-help/#findComment-856332 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? Link to comment https://forums.phpfreaks.com/topic/162242-curl-help/#findComment-856340 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. Link to comment https://forums.phpfreaks.com/topic/162242-curl-help/#findComment-856356 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. Link to comment https://forums.phpfreaks.com/topic/162242-curl-help/#findComment-856371 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.. Link to comment https://forums.phpfreaks.com/topic/162242-curl-help/#findComment-856372 Share on other sites More sharing options...
killah Posted June 16, 2009 Author Share Posted June 16, 2009 Bump Link to comment https://forums.phpfreaks.com/topic/162242-curl-help/#findComment-857284 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.