我正在嘗試從網頁中提取一些數據。但問題是,而不是拉說:編碼字符時出現CURL錯誤
64 × 191 × 75 cm
它顯示回聲作爲
64 × 191 × 75 cm
我的代碼:
<?php
$url = "http://www.google.co.uk"
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)");
curl_setopt($ch, CURLOPT_ENCODING ,"");
$html = curl_exec($ch);
$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$q_Dimensions = "//tr/td[@class='FieldTitle'][contains(.,'Dimensions of packed product (W×H×D):')]/following-sibling::td/text()";
$dimentionsQ = $xpath->query($q_Dimensions);
$dimentions = $dimentionsQ->item(0)->nodeValue;
echo $dimentions;
exit();
我相信這可能是某種問題與性格編碼但無法進一步。任何幫助深表感謝。
作品完美無瑕...感謝您的幫助和努力@Ghost非常感謝。保存了很多時間 –
@MaharshiRaval肯定的男人,沒問題 – Ghost