13-12-2008, 04:02
|
|
|
חבר מתאריך: 01.11.04
הודעות: 35
|
|
קבל דוגמה
עשיתי במיוחד בשבילך דוגמה..
הדוגמה לוקחת מה querystring פרמטר עושה חיבור עם אתר פליקס לחיפוש שלהם
ומציגה את הכותרת של התוצאות כולל לינק
מקווה שיעזור לך
קוד PHP:
$string = $_GET['string']; if($string != "") { $target_url = "http://www.flix.co.il/tapuz/Search.asp?qTxt={$string}"; $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'; $ch = curl_init(); curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); curl_setopt($ch, CURLOPT_URL,$target_url); curl_setopt($ch, CURLOPT_FAILONERROR, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); curl_setopt($ch, CURLOPT_TIMEOUT, 20); $html = curl_exec($ch); if (!$html) { echo "<br />cURL error number:" .curl_errno($ch); echo "<br />cURL error:" . curl_error($ch); exit; }
$dom = new DOMDocument(); @$dom->loadHTML($html);
$xpath = new DOMXPath($dom); $hrefs = $xpath->evaluate('/html/body//a[contains(@class, "blueFlixText") and name(b)]'); for ($i = 0; $i < $hrefs->length; $i++) { $href = $hrefs->item($i); $url = $href->getAttribute('href'); $text = $href->nodeValue;
print('<div><a href="'.$url.'">'.$text.'</a></div>'); } }
|