0

I've been searching for quite a while on how can you view search results based on a PHP form on a client's site pulling the data from Jamaican Yellow Pages.

I've found APIs for the Canadian one (http://www.yellowapi.com/), but nothing else.

I've tried using a URL with the search parameters to redirect to the Yellow Pages results page, but obviously with no luck, something like the following:

<form action="http://jamaicayp.com/Jamaica-Kingston/<?php $_GET['what']?>" 
    method="GET" class="form-input">
    <input type="text" name="what" placeholder="sometext"/>
    <input type="submit" name="some_name" value="Find"/>
</form>

Any help would be appreciated.

LSerni
  • 55,617
  • 10
  • 65
  • 107
Bialy
  • 163
  • 1
  • 9

2 Answers2

1

It is only possible if the Jamaican Yellow Pages allow API. Otherwise you can only link people to the website. Example:

<?php
$what = $_POST['what'];
$what = urlencode($what);
?>
<form action="http://jamaicayp.com/Jamaica-Kingston/<?php echo $what;?>" method="POST">
<input type="text" name="what" placeholder="sometext"/>
<input type="submit" name="some_name" value="Find"/>
</form>

urlencode is necessary for the search to contain spaces. Invalid link: something.com/search/this is bad link Good link: something.com/search/this%20is%20good%20link

1

You have an error, I think, in your code:

<?php $_GET['what']?>

should be

<?php echo $_GET['what']; ?>

This may still not work, though. If it doesn't, you need to use something like cURL.

There are two issues here: can you do this, and should you do this.

Can you do this? Yes. If you can browse to that page, you can "scrape" that page. This is my solution for PHP; others exist, and you might also want to look into "scraping libraries" and frameworks.

Should you do this? At the very least you ought to contact the webmaster and query whether it's OK to display their results on your site. In a way this is worse than hotlinking, since you're displaying results while someone else does the grunt work. That's OK for some sites, not so OK for others. It is possible to recognize when your site is being scraped, and tune your results so that the one doing the scraping gets either nothing or even something nasty. So: ask.

Community
  • 1
  • 1
LSerni
  • 55,617
  • 10
  • 65
  • 107