我试图用PHP制作一个简单的web爬虫,而且我在获取给定URL的HTML源代码时遇到了问题。我目前正在使用cURL获取源代码。
我的代码:
$url = "http://www.nytimes.com/";
function url_get_contents($Url) {
if (!function_exists('curl_init')) {
die('CURL is not installed!');
}
$ch = curl_init();
当我试图在我的本地机器上获取一些不存在的url时,大部分时间我会得到:
curl: (6) Could not resolve host: some-non-existent-url.co
然而,有时我会得到301:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanentl
我正在尝试在同一个Vagrant VM中同时运行我的API和我的客户端。在客户端中,我想使用Guzzle。当我尝试设置一个简单的测试时,我从curl得到以下错误:
Fatal error: Uncaught exception 'GuzzleHttp\Exception\RequestException' with message '[curl] (#6) See http://curl.haxx.se/libcurl/c/libcurl-errors.html for an explanation of cURL errors [url]
当我使用Github的url