<?php
$f = file_get_contents("http://www.example.com");
echo htmlspecialchars($f);
?>
将输出如何绕过外部网站目标计算机拒绝连接 - PHP的file_get_contents
<!doctype html> <html> <head> <title>Example Domain</title> <meta charset="utf-8" /> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <style type="text/css"> body { background-color: #f0f0f2; margin: 0; padding: 0; font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; } div { width: 600px; margin: 5em auto; padding: 50px; background-color: #fff; border-radius: 1em; } a:link, a:visited { color: #38488f; text-decoration: none; } @media (max-width: 700px) { body { background-color: #fff; } div { width: auto; margin: 0 auto; border-radius: 0; padding: 1em; } } </style> </head> <body> <div> <h1>Example Domain</h1> <p>This domain is established to be used for illustrative examples in documents. You may use this domain in examples without prior coordination or asking for permission.</p> <p><a href="http://www.iana.org/domains/example">More information...</a></p> </div> </body> </html>
但是如果我试着这样做:
<?php
$f = file_get_contents("http://www.yahoo.com");
echo htmlspecialchars($f);
?>
我会收到一条错误
警告:file_get_contents(http://www.yahoo.com):未能打开 流:由于目标机器 主动拒绝,因此无法建立连接。在线12上的C:\ wamp \ www \ popup.php
有没有办法解决这个问题?我想雅虎页面内得到某些HTML元素,但我在努力以这种方式
是不是你需要得到一次以上的东西吗?如果不是只是用手刮来源。 – 2014-10-29 18:28:17
是的,我应该提到,这是我需要得到不止一次,内容将可能不同于每个刮 – kamelkid2 2014-10-29 18:29:28
尝试其他的东西,然后fgc,卷曲或套接字也许? – 2014-10-29 18:30:49