/** * Get the url of the list page a link * @param string $html html source code * @return array */ function getListHref($html) { $pattern = '/[sn]*]/>/isU'; if (preg_match_all($pattern, $html, $matches)) { return $matches[1]; } else { // 没有匹配项 return array(); } }
/** * Get the next page number * @param string $html html source code * @return number */ function getListNextPage($html) { $pattern = '/]>.+>/isU'; if (preg_match($pattern, $html, $matches)) { return intval($matches[1]); } else { return -1; } }
/** * Get all hrefs in the list * @param string $keywords Search keywords * @return boolean|array */ function getListHrefAll($keywords) { if (empty($keywords)) { return false; }
(.[^<]+) if (preg_match($pattern, $html, $matches)) { $result['mfg_part'] = trim($matches[1]); } else { // This item does not exist, and the instructions are nowhere to be found return array(); }
/** * Final call function * @param string $keywords Search keywords * @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);
http://www.bkjia.com/PHPjc/728095.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/728095.htmlTechArticle复制代码 代码如下: ?php /*** HOST: www.icbase.com*/ //set_time_limit(0); // base function function curl_get($url, $data = array(), $header = array(), $timeout = 15, $port...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn