Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Curl to get specific information returned

Status
Not open for further replies.

s0crates9

Technical User
Jun 18, 2005
70
US
Hi everyone.

My problem is that I would like to use Curl on a php page to go out and use the inventory.overture.com tool for some keyword research then to return only the result that I queries for, without leaving the page or at least not displaying that it went to inventory.overture.com.

I have no idea how to use curl and would love to understand by this application of it. I tried a couple of things and they do not return what I expect. The code in case you are curious:
Code:
<?php

$HTTP_method = 'http';
$hostname = '[URL unfurl="true"]http://inventory.overture.com';[/URL]
$cgi = '/d/searchinventory/suggestion/?term=';
$domainc = '[URL unfurl="true"]www.website.com;[/URL]

$curl_handle = curl_init ();

curl_setopt ($curl_handle, CURLOPT_URL, $HTTP_method . '://' . $hostname . $cgi . $domainc);
curl_setopt ($curl_handle, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_HEADER, 1);
curl_setopt($curl_handle, CURLOPT_REFERER,"[URL unfurl="true"]http://www.website.com");[/URL]

//curl_setopt($curl_handle, CURLOPT_COOKIEFILE,"cookiefile");
//curl_setopt($curl_handle, CURLOPT_COOKIEJAR,"cookiefile");  

$result = curl_exec ($curl_handle) or die ('There has been an error');
curl_close ($curl_handle);

print $result;
?>

I appreciate any feedback, examples, fixes or tutorials.

Web site design, internet marketing, SEO and business solutions company.
 
Hi

here is you code, little changed so it works now...
..........
<?PHP
// use this so we dont get php timeout after 30 secs
set_time_limit(0);
ignore_user_abort(true);

$hostname = '$domainc = '
$curl_handle = curl_init ();

curl_setopt ($curl_handle, CURLOPT_URL, $hostname.$domainc);
curl_setopt ($curl_handle, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl_handle, CURLOPT_POST, false); // this was wrong before !
curl_setopt($curl_handle, CURLOPT_HEADER, false);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($curl_handle, CURLOPT_REFERER,"
//curl_setopt($curl_handle, CURLOPT_COOKIEFILE,"cookiefile");
//curl_setopt($curl_handle, CURLOPT_COOKIEJAR,"cookiefile");

$result = curl_exec ($curl_handle) or die ('There has been an error');
curl_close ($curl_handle);

print $result;

?>
......

you used post = true, and this was wrong...
you dont need any POST requests here, its normal http get request (and this is default in curl).

i think also url was badly formated...
and do have in mind that it sometimes takes > 30 seconds sometimes to receive the results from this script so be patient...

if you have any more problems let me know...

Regards
Slobo
 
Hi

here is you code, little changed so it works now...
..........
<?PHP
// use this so we dont get php timeout after 30 secs
set_time_limit(0);
ignore_user_abort(true);

$hostname = '$domainc = '
$curl_handle = curl_init ();

curl_setopt ($curl_handle, CURLOPT_URL, $hostname.$domainc);
curl_setopt ($curl_handle, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl_handle, CURLOPT_POST, false); // this was wrong before !
curl_setopt($curl_handle, CURLOPT_HEADER, false);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($curl_handle, CURLOPT_REFERER,"
//curl_setopt($curl_handle, CURLOPT_COOKIEFILE,"cookiefile");
//curl_setopt($curl_handle, CURLOPT_COOKIEJAR,"cookiefile");

$result = curl_exec ($curl_handle) or die ('There has been an error');
curl_close ($curl_handle);

print $result;

?>
......

you used post = true, and this was wrong...
you dont need any POST requests here, its normal http get request (and this is default in curl).

i think also url was badly formated...
and do have in mind that it sometimes takes > 30 seconds sometimes to receive the results from this script so be patient...

if you have any more problems let me know...

Regards
Slobo
 
Slobo,

Thanks for the help. I do want to adjust it though to only show only the top 5 terms from the list without the overture page showing up. So I practically want just the data from the search...

How would I go about getting that as the result?

Thanks again!

Web site design, internet marketing, SEO and business solutions company.
 
Hi

here is the code (a little spagetti code, but it works).
it shows the our title text and first 5 results without any other data...

hope its what you wanted...

you can easily customize it more... just check the code and the comments, its pretty simple stuff...


<?PHP
// use this so we dont get php timeout after 30 secs
set_time_limit(0);
ignore_user_abort(true);

$hostname = '$domainc = '
$curl_handle = curl_init ();

curl_setopt ($curl_handle, CURLOPT_URL, $hostname.$domainc);
curl_setopt ($curl_handle, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl_handle, CURLOPT_POST, false); // this was wrong before !
curl_setopt($curl_handle, CURLOPT_HEADER, false);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($curl_handle, CURLOPT_REFERER,"
//curl_setopt($curl_handle, CURLOPT_COOKIEFILE,"cookiefile");
//curl_setopt($curl_handle, CURLOPT_COOKIEJAR,"cookiefile");

$result = curl_exec ($curl_handle) or die ('There has been an error');
curl_close ($curl_handle);

// extract HTML tables from the resuts
preg_match_all("/<table (.*?)<\/table>/is",$result,$match);

// we want only one with the results
$resultstable = $match[0][1];


// now extract all the rows from table with results
preg_match_all("/<tr(.*?)<\/tr>/is",$resultstable,$match);

$rows = $match[0];

print("<p> Results for keyword: ".$domainc." </p>");

// now print a new table, skip the first 2 rows (header) and then print only the next 5 result rows
print("<table>");
for ($i = 2; $i < 7; $i++)
print($rows[$i]);
print("</table>");

?>


regards
Slobo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top