最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2014年01月30日 23:11:40   作者:  
這篇文章主要介紹了分享下頁(yè)面關(guān)鍵字抓取components.arrow.com站點(diǎn)代碼的相關(guān)資料,需要的朋友可以參考下

復(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)后的頁(yè)面
 $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;
 }

/**
 * 獲取列表頁(yè)的html源碼
 * @param string $keywords 搜索關(guān)鍵字
 * @param int $start 開(kāi)始記錄數(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;
 }

/**
 * 獲取列表頁(yè) 連接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 {
 // 沒(méi)有匹配項(xiàng)
 return array();
 }
 }

/**
 * 獲取下一頁(yè)數(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;
 }
 }

/**
 * 獲取列表也所有的詳細(xì)列表
 * @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))
 {
 // 沒(méi)有結(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;
 }

/**
 * 獲取詳情頁(yè)信息
 * @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' => '', // 制造商型號(hào)
 'mfg_name' => '', // 制造商名稱
 'cat_name' => '', // 分類名稱
 'para' => '', // 屬性
 'desc' => '', // 描述
 'pdf_url' => '', // PDF地址
 'sup_stock' => '', // 庫(kù)存
 'min_purch' => '', // 最小訂購(gòu)量
 'price' => '', // 價(jià)格
 'img_url' => '', // 圖片地址
 'createtime' => '', // 創(chuàng)建時(shí)間
 'datacode' => '', // 批號(hào)
 'package' => '', // 封裝
 'page_url' => '', // 頁(yè)面地址
 );

// 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('&amp;', '&', $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);

相關(guān)文章

  • PHP把小數(shù)轉(zhuǎn)成整數(shù)3種方法

    PHP把小數(shù)轉(zhuǎn)成整數(shù)3種方法

    這篇文章主要介紹了PHP把小數(shù)轉(zhuǎn)成整數(shù)3種方法,實(shí)際上是使用的PHP自帶的3個(gè)函數(shù),分別是floor、ceil和round,需要的朋友可以參考下
    2014-06-06
  • PHP Opcache安裝和配置方法介紹

    PHP Opcache安裝和配置方法介紹

    這篇文章主要介紹了PHP Opcache安裝和配置方法介紹,Opcache的安裝需要在編譯時(shí)加上enable-opcache即可,本文著重講解配置方法,需要的朋友可以參考下
    2015-05-05
  • phpcms中的評(píng)論樣式修改方法

    phpcms中的評(píng)論樣式修改方法

    phpcms中自帶的評(píng)論插件很好用,但是樣式不太好看,今天小編給大家分享兩種關(guān)于phpcms中的評(píng)論樣式修改方法,一起看看吧
    2016-10-10
  • Zend Framework分發(fā)器用法示例

    Zend Framework分發(fā)器用法示例

    這篇文章主要介紹了Zend Framework分發(fā)器用法,結(jié)合實(shí)例形式分析了Zend Framework分發(fā)器的功能、定義及簡(jiǎn)單使用方法,需要的朋友可以參考下
    2016-12-12
  • windwos下使用php連接oracle數(shù)據(jù)庫(kù)的過(guò)程分享

    windwos下使用php連接oracle數(shù)據(jù)庫(kù)的過(guò)程分享

    這篇文章主要介紹了windwos下使用php連接oracle數(shù)據(jù)庫(kù)的過(guò)程分享,講解了php連接oracle的必要條件、代碼實(shí)例以及錯(cuò)誤排查等,需要的朋友可以參考下
    2014-05-05
  • PHP生成唯一訂單號(hào)的方法匯總

    PHP生成唯一訂單號(hào)的方法匯總

    前陣子有個(gè)電子商務(wù)項(xiàng)目,需要生成訂單號(hào)。當(dāng)時(shí)的考慮很簡(jiǎn)單,取系統(tǒng)時(shí)間加上隨機(jī)數(shù),或者使用 uniqid() 方法。仔細(xì)考慮下上述方法,在顧客購(gòu)買(mǎi)量少的情況下,訂單重復(fù)的可能性為零,但是在購(gòu)買(mǎi)高蜂期生成的訂單號(hào)重復(fù)是很有可能發(fā)生的。
    2015-04-04
  • php制作unicode解碼工具(unicode編碼轉(zhuǎn)換器)代碼分享

    php制作unicode解碼工具(unicode編碼轉(zhuǎn)換器)代碼分享

    php制作Unicode編碼解碼在線轉(zhuǎn)換工具代碼分享
    2013-12-12
  • 我整理的PHP 7.0主要新特性

    我整理的PHP 7.0主要新特性

    截止到目前為止,PHP官方已經(jīng)發(fā)布了php7的RC5版本,預(yù)計(jì)在11月份左右會(huì)發(fā)布第一個(gè)正式版本!現(xiàn)在來(lái)說(shuō)php7的重大特性肯定已經(jīng)是定型了,不會(huì)再有什么變動(dòng)了。后續(xù)一些版本的迭代主要也就是修修bug,優(yōu)化之類的。下面就來(lái)說(shuō)話我們一直期待的php7.0新特征吧
    2016-01-01
  • Yii使用CLinkPager分頁(yè)實(shí)例詳解

    Yii使用CLinkPager分頁(yè)實(shí)例詳解

    這篇文章主要介紹了Yii使用CLinkPager分頁(yè)的方法,需要的朋友可以參考下
    2014-07-07
  • CI框架源碼解讀之利用Hook.php文件完成功能擴(kuò)展的方法

    CI框架源碼解讀之利用Hook.php文件完成功能擴(kuò)展的方法

    這篇文章主要介紹了CI框架源碼解讀之利用Hook.php文件完成功能擴(kuò)展的方法,分析了Hook的原理與擴(kuò)展CI框架的相關(guān)技巧,需要的朋友可以參考下
    2016-05-05

最新評(píng)論

旬邑县| 比如县| 伊春市| 巴南区| 屏南县| 焦作市| 哈尔滨市| 桂林市| 郸城县| 汾西县| 淮阳县| 行唐县| 孟津县| 新龙县| 铁岭市| 海宁市| 乡城县| 临邑县| 山丹县| 饶平县| 呼伦贝尔市| 贡嘎县| 大荔县| 宁陕县| 三亚市| 溧水县| 墨竹工卡县| 罗城| 龙门县| 庆元县| 文水县| 太康县| 丰镇市| 刚察县| 云南省| 页游| 辽阳县| 大厂| 西乌珠穆沁旗| 康马县| 昭觉县|