error fetching document: connection failed ()

P!@y3r
2007-04-06
2013-05-30
  • P!@y3r
    P!@y3r
    2007-04-06

    i get that error when i access the url of the page where i have this code

    <?
    header("Content-type: text/html; charset=utf-8");

    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
            1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
            xml:lang="en" lang="en">
    <head>
        <title>PHP5 Screen-Scraping</title>
    </head>
    <body>

    <?

    $dom = new domdocument;

    $url = 'http://news.google.com';

    @$dom->loadHTMLFile($url);

    $xpath = new domxpath($dom);
    $xNodes = $xpath->query('//a[@class="y"]');
    echo '<h1>Google News Headlines</h1>';
    echo '<ul>';
    foreach ($xNodes as $xNode)
    {
        $sLinktext = @$xNode->firstChild->data;
        $sLinkurl = $xNode->getAttribute('href');

        if ($sLinktext != '' && $sLinkurl != '')
        {
            echo '<li><a href="' . $sLinkurl . '">' .
                    $sLinktext . '</a></li>';
            echo "\r\n";
        }
    }
    echo '</ul>';
    ?>

    </body>
    </html>

    My directory structure is this

    snoop
    |
    |____Snoopy.class.php
    |____URL_to_the_above_code_file

     
    • P!@y3r
      P!@y3r
      2007-04-06

      sorry this is the real code of the page

          <?php
          include "Snoopy.class.php";
          $snoopy = new Snoopy;
         
          $snoopy->user = "joe";
          $snoopy->pass = "bloe";
         
          if($snoopy->fetch("http://www.yahoo.com"))
          {
              echo "response code: ".$snoopy->response_code."<br>\n";
              while(list($key,$val) = each($snoopy->headers))
                  echo $key.": ".$val."<br>\n";
              echo "<p>\n";
             
              echo "<PRE>".htmlspecialchars($snoopy->results)."</PRE>\n";
          }
          else
              echo "error fetching document: ".$snoopy->error."\n";
              ?>