天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

分享下頁面關(guān)鍵字抓取components.arrow.com站點代碼

復(fù)制代碼 代碼如下:
<?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); //是否抓取跳轉(zhuǎn)后的頁面
 $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;
 }

復(fù)制代碼 代碼如下:
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 搜索關(guān)鍵字
 * @param int $start 開始記錄數(shù)
 * @return boolean|array
 */
 function getListHtml($keywords, $start = 0)
 {
 if ($start < 0)
 {
 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 = '/<td/s+class="col_mfr_part_num"><a/s+href="(.[^>]+)">/isU';
 if (preg_match_all($pattern, $html, $matches))
 {
 return $matches[1];
 } else {
 // 沒有匹配項
 return array();
 }
 }

/**
 * 獲取數(shù)字start
 * @param string $html html源碼
 * @return number
 */
 function getListNextPage($html)
 {
 $pattern = '/<script/s+language="Javascript">buildPagination/(/'/d+/',/'/d+/',/'(/d+)/',/d+/);<//script>/isU';
 if (preg_match($pattern, $html, $matches))
 {
 return intval($matches[1]);
 } else {
 return -1;
 }
 }

/**
 * 獲取列表也所有的詳細列表
 * @param string $keywords 搜索關(guān)鍵字
 * @return boolean|array
 */
 function getListHrefAll($keywords)
 {
 if (empty($keywords))
 {
 return false;
 }

$html = getListHtml($keywords);
 $hrefList = getListHref($html);
 if (empty($hrefList))
 {
 // 沒有結(jié)果
 return array();
 }
 $nextPage = getListNextPage($html);
 $loop =0;
 while ($nextPage > 0)
 {
 $html = getListHtml($keywords, $nextPage);
 $tmpHrefList = getListHref($html);
 $hrefList = array_merge($hrefList, $tmpHrefList);
 $nextPage = getListNextPage($html);
 $loop ++;
 }
 return $hrefList;
 }

/**
 * 獲取詳情頁信息
 * @param string $url url地址
 * @return array()
 */
 function getDetail($url)
 {
 if ( empty($url) )
 {
 return false;
 }
 $host = 'http://components.arrow.com';

$url = $host . $url;
 $result = curl_get($url);
 if ( isset($result['error']) )
 {
 return array();
 //exit($result['error']);
 }
 $html = $result['result'];

$result = array(
 'sup_part' => '', // 供應(yīng)商型
 'sup_id' => '', // 供應(yīng)商ID
 'mfg_part' => '', // 制造商型號
 'mfg_name' => '', // 制造商名稱
 'cat_name' => '', // 分類名稱
 'para' => '', // 屬性
 'desc' => '', // 描述
 'pdf_url' => '', // PDF地址
 'sup_stock' => '', // 庫存
 'min_purch' => '', // 最小訂購量
 'price' => '', // 價格
 'img_url' => '', // 圖片地址
 'createtime' => '', // 創(chuàng)建時間
 'datacode' => '', // 批號
 'package' => '', // 封裝
 'page_url' => '', // 頁面地址
 );

// mfg_part
 $pattern = '/<li>[/s/n]*<strong>Part No:/s*<//strong>(.+)<//li>/isU';
 if (preg_match($pattern, $html, $matches))
 {
 $result['mfg_part'] = trim($matches[1]);
 } else {file_put_contents('page.txt', $html);die('xxx');
 return array();
 }

// mfg_name
 $pattern = '/<li>[/s/n]*<strong>Manufacturer: <//strong>(.+)<//li>/isU';
 if (preg_match($pattern, $html, $matches))
 {
 $result['mfg_name'] = trim($matches[1]);
 }

// cat_name
 $pattern = '/displayCategory/(/'(.[^/']+)/'/);/isU';
 if (preg_match($pattern, $html, $matches))
 {
 $result['cat_name'] = trim($matches[1]);
 $result['cat_name'] = str_replace('|', '>', $result['cat_name']);
 }

// para
 $tablepattern = '/<table/s+id="part_specs".[^>]*>(.+)<//table>/isU';
 if (preg_match($tablepattern, $html, $matches))
 {
 $pattern = '/<tr>[/s/n]*<td><strong>(.+)<//strong><//td><td>(.+)<//td>[/s/n]*<//tr>/isU';
 if (preg_match_all($pattern, $matches[1], $matches))
 {
 foreach($matches[1] as $k=>$v)
 {
 $v = trim($v);
 if ('Package Type' == $v)
 {
 $result['package'] = trim($matches[2][$k]);
 continue;
 }
 $result['para'][$v] = trim($matches[2][$k]);
 }
 }
 }

// desc
 $pattern = '/<div/s+id="part_title">.+<h4>(.+)<//h4>[/s/n]*<//div>/isU';
 if (preg_match($pattern, $html, $matches))
 {
 $result['desc'] = trim($matches[1]);
 }

// pdf_url
 $pattern = '/<li/s+class="datasheet">[/s/n]*<strong>Datasheet:<//strong><a/s+href="(.[^"]+)"/isU';
 if (preg_match($pattern, $html, $matches))
 {
 $result['pdf_url'] = $host . trim($matches[1]);
 }

// sup_stock
 $pattern = '/<td/s+id="inv_1"/s+class="li_inv">([/d,]+)<//td>/isU';
 if (preg_match($pattern, $html, $matches))
 {
 $result['sup_stock'] = trim($matches[1]);
 $result['sup_stock'] = str_replace(',', '', $result['sup_stock']);
 }

// min_purch
 $pattern = '/<span/s+id="multiples">[/s/n]*<strong>Multiple:/s*<//strong>(.+)<//span>/isU';
 if (preg_match($pattern, $html, $matches))
 {
 $result['min_purch'] = trim($matches[1]);
 }

// price
 $pattern = '/<div/s+id="price_1"/s+class="li_price">(.[^<]+)<//div>/isU';
 if (preg_match($pattern, $html, $matches))
 {
 $result['price'][1] = trim($matches[1]);
 }
 $pattern = '/<div/s+id="price_1"/s+class="li_price">[/s/n]*<span.[^>]+title="(.[^"]+)">/isU';
 if (preg_match($pattern, $html, $matches))
 {
 $priceurl = str_replace('&', '&', $matches[1]);
 $json = curl_get($priceurl);
 $json = $json['result'];
 if (! empty($json))
 {
 $jsonresult = json_decode($json, true);
 foreach ($jsonresult['parts'][0]['webprice']['resale'] as $k=>$v)
 {
 $result['price'][$v['minqty']] = $v['price'];
 }
 }
 }

// img_url
 $pattern = '/<div/s+id="part_image">[/s/n]*<img/s+src="(.[^"]+)"/isU';
 if (preg_match($pattern, $html, $matches))
 {
 $result['img_url'] = trim($matches[1]);
 }

// page_url
 $result['page_url'] = $url;

return $result;
 }

/**
 * 最終調(diào)用函數(shù)
 * @param string $keywords 搜索關(guān)鍵字
 * @return array
 */
 function getData($keywords)
 {
 $hrefList = getListHrefAll($keywords);
 $result = array();

foreach ($hrefList as $k=>$v)
 {
 $result[] = getDetail($v);
 }

return $result;
 }

// Test Script
 $keywords = trim($_GET['keywords']);
 $result = getData($keywords);

print_r($result);

php技術(shù)分享下頁面關(guān)鍵字抓取components.arrow.com站點代碼,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: BLACKED太粗太长 | 116美女写真成人午夜视频 | 久爱在线中文在观看 | 久久re热在线视频精99 | 妹妹我要色 | 欧美精品AV精品一区视频 | 97国产成人精品免费视频 | 最近中文字幕MV高清在线视频 | 午夜国产高清精品一区免费 | 久久99综合国产精品亚洲首页 | 亚洲精品无码不卡 | 亚洲黄色免费观看 | 久久免费电影 | 国产视频这里只有精品 | 天天夜夜草草久久亚洲香蕉 | 亚洲m男在线中文字幕 | 爱情岛aqdlttv | 午夜爱情动作片P | 亚洲精品一二三区区别在哪 | 91系列在线观看免费 | 精品国产自在天天线2019 | 亚洲精品AV无码重口另类 | 国产精品99久久免费黑人人妻 | 国精产品一区二区三区四区糖心 | 最新影音先锋av资源台 | 乱码国产丰满人妻WWW | 亚洲精品不卡视频 | 国产 高清 无码 在线播放 | 正在播放国产精品 | 亚洲成年人在线观看 | 同时和两老师双飞 | 九九精彩视频在线观看视频 | 亚洲 欧美 日韩 国产 视频 | 国产1广场舞丰满老女偷 | 亚洲精品在线影院 | 亚洲精品免播放器在线观看 | 亚洲AV人无码综合在线观看蜜桃 | 国产免费内射又粗又爽密桃视频 | 国产精品A久久久久久久久 国产精品A久久777777 | 毛片免费观看 | 久久激情网 |