【发布时间】:2017-03-21 18:59:36
【问题描述】:
我正在使用 proxymillion 从谷歌抓取数据。我正在使用 cURL 但没有得到结果并得到错误 Error 405 (Method Not Allowed)!!1
我的代码
$proxies[] = 'username:password@IP:port'; // Some proxies require user, password, IP and port number
$proxies[] = 'username:password@IP:port'; // Some proxies require user, password, IP and port number
$proxies[] = 'username:password@IP:port'; // Some proxies require user, password, IP and port number
$proxies[] = 'username:password@IP:port'; // Some proxies require user, password, IP and port number
if (isset($proxies)) { // If the $proxies array contains items, then
$proxy = $proxies[array_rand($proxies)]; // Select a random proxy from the array and assign to $proxy variable
}
$ch = curl_init();
if (isset($proxy)) { // If the $proxy variable is set, then
curl_setopt($ch, CURLOPT_PROXY, $proxy); // Set CURLOPT_PROXY with proxy in $proxy variable
}
$url="https://www.google.com.pk/?gws_rd=cr,ssl&ei=8kXQWNChIsTSvgSZ3J24DA#q=pakistan&*";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
// curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
// curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$page = curl_exec($ch);
curl_close($ch);
$dom = new simple_html_dom();
$html = $dom->load($page);
$title=$html->find("title",0);
echo $title->innertext;
【问题讨论】:
-
您百分百确定您正在测试的服务允许使用 PUT 方法?
-
@takendarkk 不,从互联网上获得一些帮助,但它没有用..当我删除包含“PUT”的内容时,页面变为空白
-
好吧,您需要阅读有关该服务的信息并找到它允许的方法。
-
@takendarkk 你有这样的示例代码吗?这可能会有所帮助,我试过这个scrape-google-search.compunect.com 但没有成功
-
我不知道您为什么认为示例代码会有所帮助。在编写任何代码之前,您首先需要找出 Web 服务允许您调用的方法。没有这些信息,其他任何事情都不重要。
标签: php curl web-scraping