分享下页面关键字抓取components.arrow.com站点代码_PHP
/**
* HOST: components.arrow.com
*/
//set_time_limit(0);
// base function
function curl_get($url, $data = array(), $header = array(), $timeout = 15, $port = 80, $reffer = '', $proxy = '')
{
$ch = curl_init();
if (!empty($data)) {
$data = is_array($data)?http_build_query($data): $data;
$url .= (strpos($url,'?')? '&': "?") . $data;
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_PORT, $port);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //是否抓取跳转后的页面
$reffer && curl_setopt($ch, CURLOPT_REFERER, $reffer);
if($proxy) {
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYPORT, 1723);
curl_setopt($ch, CURLOPT_PROXYUSERPWD,"andhm001:andhm123");
}
$result = array();
$result['result'] = curl_exec($ch);
if (0 != curl_errno($ch)) {
$result['error'] = "Error:\n" . curl_error($ch);
}
curl_close($ch);
return $result;
}
复制代码 代码如下:
function curl_post($url, $data = array(), $header = array(), $timeout = 15, $port = 80)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_PORT, $port);
!empty ($header) && curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = array();
$result['result'] = curl_exec($ch);
if (0 != curl_errno($ch)) {
$result['error'] = "Error:\n" . curl_error($ch);
}
curl_close($ch);
return $result;
}
/**
* 获取列表页的html源码
* @param string $keywords 搜索关键字
* @param int $start 开始记录数
* @return boolean|array
*/
function getListHtml($keywords, $start = 0)
{
if ($start {
return false;
}
$postData = array(
'search_token' => $keywords,
'start' => $start,
'limit' => 100,
);
$result = curl_post('http://components.arrow.com/part/search/' . $keywords, http_build_query($postData));
if ( isset($result['error']) )
{
return false;
//exit($result['error']);
}
$result = $result['result'];
return $result;
}
/**
* 获取列表页 连接href
* @param string $html html源码
* @return array
*/
function getListHref($html)
{
$pattern = '/
推荐阅读
-
分享下页面关键字抓取components.arrow.com站点代码_PHP
-
分享下页面关键字抓取www.icbase.com站点代码(带asp.net参数的)
-
分享下页面关键字抓取components.arrow.com站点代码
-
分享下页面关键字抓取www.icbase.com站点代码(带asp.net参数的)_PHP
-
分享下页面关键字抓取components.arrow.com站点代码_PHP教程
-
分享下页面关键字抓取components.arrow.com站点代码
-
分享下页面关键字抓取www.icbase.com站点代码(带asp.net参数的)
-
分享下页面关键字抓取www.icbase.com站点代码(带asp.net参数的)
-
分享下页面关键字抓取components.arrow.com站点代码_php实例
-
分享下页面关键字抓取components.arrow.com站点代码