分享下页面关键字抓取components.arrow.com站点代码
php  /  管理员 发布于 7年前   152
$result = array(); } $result = array(); } return $result; /** $postData = array( $result = curl_post('http://components.arrow.com/part/search/' . $keywords, http_build_query($postData)); return $result; /** /** 122 在 123 在 原梓番博客 在 博主 在 1111 在
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号
/**
* 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['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['result'] = curl_exec($ch);
if (0 != curl_errno($ch)) {
$result['error'] = "Error:\n" . curl_error($ch);
curl_close($ch);
}
* 获取列表页的html源码
* @param string $keywords 搜索关键字
* @param int $start 开始记录数
* @return boolean|array
*/
function getListHtml($keywords, $start = 0)
{
if ($start < 0)
{
return false;
}
'search_token' => $keywords,
'start' => $start,
'limit' => 100,
);
if ( isset($result['error']) )
{
return false;
//exit($result['error']);
}
$result = $result['result'];
}
* 获取列表页 连接href
* @param string $html html源码
* @return array
*/
function getListHref($html)
{
$pattern = '/]+)">/isU';
if (preg_match_all($pattern, $html, $matches))
{
return $matches[1];
} else {
// 没有匹配项
return array();
}
}
* 获取下一页数字start
* @param string $html html源码
* @return number
*/
function getListNextPage($html)
{
$pattern = '/