<?php
/**
* WiseLoop PHP Web Grabber Sample<br/>
* Title: Yahoo Search
* Description: Get Yahoo Search Results
* Web Search Engine Simulation: fetching Yahoo Search results within your own page
*/
//get the search phrase
$q = str_replace(" ", "+", wlExtArray::getArrayValue($_POST, "q", wlExtArray::getArrayValue($_GET, "q", "")));
//get the page
$p = intval(wlExtArray::getArrayValue($_POST, "p", wlExtArray::getArrayValue($_GET, "p", 1)));
?>
<!-- form start -->
<form action="" id="form" method="POST" enctype="multipart/form-data" class="form-horizontal" role="form">
<input type="hidden" id="demo" name="demo" value="yahoo"/>
<div class="form-group">
<label for="q" class="col-sm-2 control-label">Search phrase:</label>
<div class="col-sm-10">
<input class="form-control" type="text" name="q" id="q" placeholder="Search" value="<?php echo $q != "" ? $q : "WiseLoop"; ?>"/>
</div>
</div>
<div class="form-group">
<label for="p" class="col-sm-2 control-label">Page:</label>
<div class="col-sm-10">
<select class="form-control" name="p" id="p" onchange="document.forms['form'].submit();">;
<?php
for ($i = 1; $i < 10; $i++)
echo '<option ' . ($p == $i ? 'selected' : '') . ' value="' . $i . '">' . $i . '</option>';
?>
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" value="Yahoo Search" class="btn btn-primary"/>
</div>
</div>
</form>
<!-- form end -->
<?php
if ($q) {
//compute the url using the given search phrase and page
$b = ($p - 1) * 10 + 1;
$url = 'http://search.yahoo.com/search?p=' . $q . '&b=' . $b;
$prm = new wlWgParam('<ol class="mb-'); //the desired tag to be extracted, this is only a slice tag
echo '<div class="well well-small">';
echo '<h3 class="color-caption">Grabbed content from <a style="font-weight:bold;" target="_blank" href="' . $url . '">' . $url . '</a></h3>';
//here is the magic: creating the Yahoo Search grabber processor object using the computed url and tag to extract
$wp = new wlWgProcessor(
$url, //the targeted real url
$prm, //the grabbing parameter
0 //no caching needed - it's a search engine :)
);
//you can also use specialized grabber from the library that implements the code above
//$wp = new wlWgYahooSearch($q, $p);
//grab and draw the contents
//$wp->draw();
$result = $wp->get();
echo $result[0][0];
echo '</div>';
}