PHP获取淘宝产品描述和产品参数

放代码,首先curl_setopt,这个就不解释了。

function curl_get($url) {
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
	curl_setopt($ch, CURLOPT_HEADER, false);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_REFERER, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
	$result = curl_exec($ch);
	curl_close($ch);
	return $result;
}

然后就是核心代码了:

function taobao($url) {
        $ff = curl_get($url);
        $ff = trim(mb_convert_encoding($ff, "UTF-8", "GBK"));
		$f0 = explode("class=\"attributes-list\">", $ff);
		$f0 = explode("</ul>", $f0[1]);
		$f0 = $f0[0];
		$arr[0] = "<ul class=\"attributes-list\">" . $f0 . "</ul>";
		$f1 = explode("location.protocol===", $ff);
		$f1 = explode(",", $f1[1]);
		$f1 = str_replace("'", "", $f1);
		$f1 = str_replace(":", "", $f1);
		$f1 = explode("//", $f1[0]);
		if (empty($f1[0]))
			return array();
		$f1 = "http://" . $f1[1];
        $data = substr(trim(file_get_contents($f1)), 10, -2);
		$data = mb_convert_encoding($data, "UTF-8", "GBK");
		$arr[1] = $data;
        return $arr;
}

其中。arr[0]是淘宝产品参数,arr[1]是淘宝产品描述

  • 时间:2017-02-09 11:31:00
  • 分类:zblogphp
  • 浏览:1513
  • 评论:
备案号:豫ICP备12024521号
Powered By Z-BlogPHP 技术支持:唐朝