Exemplo n.º 1
0
 function Search($keyword)
 {
     $uri = 'http://www.77nt.com/SoClass.aspx';
     $data = 'class=' . urlencode(iconv("UTF-8", "gb2312", $keyword)) . '&submit=&ctl00%24Sodaohang=';
     $html = http_post($uri, $data);
     $html = str_replace("text/html; charset=gb2312", "text/html; charset=gb18030", $html);
     $xpath = new XPath($html);
     $options = $xpath->query("//div[@class='page']/form/select/option");
     $i = 0;
     $books = array();
     $pages = array();
     foreach ($options as $option) {
         $value = $option->getattribute('value');
         if ($value != '0') {
             $pages[] = 'http://www.77nt.com/Soclass.aspx?class=' . urlencode(iconv("UTF-8", "gb2312", $keyword)) . "&page=" . $i;
         }
         ++$i;
     }
     // page 1
     $result = array();
     $result[0] = $this->__ParseBooks($html);
     // other pages
     if (count($pages) > 0) {
         $http = new HttpMultipleProxy("proxy.cfg");
         $r = $http->get($pages, array($this, '_OnReadBook'), &$result, 60);
         if (0 != $r) {
             // log error
         }
     }
     if (count($pages) == count($result)) {
         for ($i = 0; $i < count($result); $i++) {
             foreach ($result[$i] as $bid => $book) {
                 $books[$bid] = $book;
             }
         }
     }
     return array("book" => $books);
 }
Exemplo n.º 2
0
 function GetBooks($uri)
 {
     $html = $this->http->get($uri, "Ysjs/bot.js");
     //file_put_contents ("1.html", $html);
     $html = str_replace("text/html; charset=gb2312", "text/html; charset=gb18030", $html);
     $doc = dom_parse($html);
     if (0 == strcmp($uri, 'http://www.ysts8.com/index_tim.html')) {
         $books = $this->__ParseBooks($html);
     } else {
         if (0 == strcmp($uri, 'http://www.ysts8.com/index_hot.html')) {
             $books = $this->__ParseBooks($html);
         } else {
             $options = xpath_query($doc, "//select[@name='select']/option");
             $books = $this->__ParseBooks($html);
             $host = parse_url($uri);
             $urls = array();
             foreach ($options as $option) {
                 $href = $option->getattribute('value');
                 if (strlen($href) > 0) {
                     $u = 'http://' . $host["host"] . dirname($host["path"]) . '/' . $href;
                     if (0 != strcmp($u, $uri)) {
                         $urls[] = $u;
                     }
                 }
             }
             $result = array();
             $http = new HttpMultipleProxy("proxy.cfg");
             $r = $http->get($urls, array($this, '_OnReadBook'), &$result, 20);
             if (count($result) != count($urls)) {
                 assert(0 != $r);
                 $books = array();
                 // empty data(some uri request failed)
             } else {
                 for ($i = 0; $i < count($result); $i++) {
                     foreach ($result[$i] as $id => $name) {
                         $books[$id] = $name;
                     }
                 }
             }
         }
     }
     $data = array();
     $data["icon"] = "";
     $data["book"] = $books;
     return $data;
 }