Jump to content
MakeWebGames

curl help


Ben Nash

Recommended Posts

I'm trying to grab job listings from job sites like reed.com.

 

<?php
include("config.php");

echo"
<form action='index.php' method='POST' />
What: <input type='text' name='what' /> 
Where: <input type='text' name='where' />
<input type='submit' name='search' value='Search'/> 
</form>";

if (isset($_POST['search'])) {

$what = mysql_real_escape_string($_POST['what']);
$where = mysql_real_escape_string($_POST['where']);

if (empty($what) && (empty($where)))  {
echo"You need to enter info";
}else{

$curl = curl_init("http://www.reed.co.uk/jobs/$what-in-$where");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);

$page = curl_exec($curl);

curl_close($curl);

$regex = '/<p class="description">(.*?)<\/p>/s';
if ( preg_match($regex, $page, $list) )
   echo $list[0];

}

echo"<a href='http://www.reed.co.uk/jobs/$what-in-$where'>Continue</a>";

}

?>

 

This is my current code. If you enter info into the fields a link will appear for testing purposes, click on it and it will take you to reed. You will see the data entered at my site is all stuffed into the location field on reed. This is causing my site to display incorrect data... What am I doing wrong?

Link to comment
Share on other sites

That fixed the link but It's not displaying the full listing on my site. I have a strong belief this is the issue:
$regex = '/<p class="description">(.*?)<\/p>/s';

$url = 'http://www.reed.co.uk/jobs/'.$where.'?keywords='.$what;
$curl = curl_init ( $url );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);

$page = curl_exec($curl);

curl_close($curl);

$regex = '/<p class="description">(.*?)<\/p>/s';
if ( preg_match_all ( $regex, $page, $matches ) ) {
   $matches = $matches[0]; // Want the <p> ? no? use $matches[1]; then.
   foreach ( $matches as $key => $val ) {
       echo 'Match('.$key.'): '.htmlentities ( $val, ENT_QUOTES, 'UTF-8' ).' <br />';
   }
}
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...