20.12.2012, 18:29
|
Start Post: помогите с пхп пожалуйста
|
Senior Member
Регистрация: 08.10.2009
Сообщений: 792
Бабло: $157765
|
если кто может, допилите плиз скрипт, чтоб можно было в урл задавать параметр запроса, передавать его в скрипт,
и чтоб выводило на странице результат парсинга:
PHP код:
<?php
class Bing
{
#парсинг Bing
public function Start($string, $language, $browser, $count = null)
{
$query = urlencode(mb_strtolower($string, 'UTF-8'));
$url = "http://www.bing.com/search?q=$query+language:$language";
$html = file_get_html($url, false, stream_context_create(array(
'http' => array(
'method' => "GET",
'header' => "Accept-Language: $language\r\n" . "Host: www.bing.com\r\n" . "User-Agent: $browser\r\n"
)
)));
$snippets = array();
if (!is_bool($html))
{
$i = 0;
foreach ($html->find('ul[id="wg0"] li') as $e)
{
$t = 'div[class="sa_cc"] div[class="sb_tlst"] h3 a';
$d = 'div[class="sa_cc"] p';
if (isset($e->find($t, 0)->plaintext))
{
$title = $e->find($t, 0)->plaintext;
}
if (isset($e->find($d, 0)->plaintext))
{
$description = $e->find($d, 0)->plaintext;
}
if ($i < $count)
{
if (!empty($title) and !empty($description))
{
$snippets[$i]['title'] = trim($title);
$snippets[$i]['description'] = trim($description);
$i++;
}
}
}
$html->clear();
$html = null; $e = null;
unset($html, $e);
}
else
{
echo "error";
}
return $snippets;
}
}
|
|
|