function Parse($response) { $doc = dom_parse($response); $elements = xpath_query($doc, "//div[@class='cont_font']/p"); $proxies = array(); foreach ($elements as $element) { foreach ($element->childNodes as $node) { if (XML_TEXT_NODE == $node->nodeType) { $value = $node->nodeValue; $n = strpos($value, "@"); if ($n > 0) { $proxies[] = trim(substr($value, 0, $n)); } } } } return $proxies; }
function __SearchPageCount($response) { $doc = dom_parse($response); $pages = xpath_query($doc, "//ul[@class='pagelist']/table/tr/td/center/font/b/a[4]"); if (!is_null($pages)) { foreach ($pages as $page) { $href = $page->getattribute('href'); if (strlen($href) > 0) { if (1 == sscanf($href, "page=%d", $n)) { return $n; } } } } return 1; }
function zol_wallpaper_catalog($uri) { $response = http_get($uri); $response = str_replace("text/html; charset=gb2312", "text/html; charset=gb18030", $response); $doc = dom_parse($response); $elements = xpath_query($doc, "//dl[@class='filter-item first clearfix']/dd"); $catalog = array(); if (!is_null($elements)) { $host = parse_url($uri); foreach ($elements as $element) { $nodes = $element->childNodes; foreach ($nodes as $node) { if (XML_ELEMENT_NODE == $node->nodeType) { $href = $node->getAttribute('href'); if (strlen($href) > 0) { //$catalog[$node->nodeValue] = zol_wallpaper_subcatalog('http://sj.zol.com.cn' . $href); $catalog[$node->nodeValue] = 'http://' . $host["host"] . $href; } } } } } return $catalog; }