【问题标题】:Proxymillion IPs with cURL使用 cURL 代理百万 IP
【发布时间】: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


【解决方案1】:

如果我猜对了,您正在寻找用于抓取 Google 的预算解决方案,这就是为什么您在 cmets 中链接的示例代码中切换到 proxymillion 提供商?

您无法使用大量共享的代理(即您使用的提供商)进行抓取,Google 会直接或在几页内发现它们并阻止。
也使用“&ei=8kXQWNChIsTSvgSZ3J24DA”不是最好的主意,这不是谷歌的默认条目,并且可能会将您的抓取请求与您的浏览器链接(您最初拥有该参数)。

如果您寻找预算解决方案,您可以考虑使用抓取服务(此处的 php 源代码:http://scraping.services/?api&chapter=Source%20Code),在大多数情况下,它比私人代理便宜,并且可以以几美元的价格抓取一万个关键字。

或者,如果您想继续这条路线,我建议您使用简单的 bash 脚本测试您的 proxymillion 性能。
在 bash 脚本中使用 curl 或 lynx(如果您使用 linux,否则您可以在 Windows 上使用 MinGW/msys 执行相同操作),然后让他们使用代理访问 Google。看看它是否有效,或者您是否在几页内被阻止。
但即使你成功了:任何共享代理提供者在“性能”上都会不可靠。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-08
    • 1970-01-01
    • 2017-08-26
    • 2013-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多