modstore / rotating-proxy-bundle

该软件包的最新版本(dev-master)没有可用的许可信息。

Symfony的轮换代理包。

安装次数:4,204

依赖关系: 0

建议者: 0

安全: 0

星标: 2

关注者: 1

分支: 1

开放问题: 0

类型:symfony-bundle

dev-master 2019-01-03 00:43 UTC

This package is auto-updated.

Last update: 2024-09-06 12:10:28 UTC


README

此包在发送后续请求时会在您的HTTP代理池中轮换。

安装

composer require modstore/rotating-proxy-bundle:dev-master

将RotatingProxyBundle添加到您的应用内核

// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new Modstore\RotatingProxyBundle\ModstoreRotatingProxyBundle(),
        // ...
    );
}

添加您的代理池

将您的代理IP地址添加到数据库表:modstore_rotating_proxy

  • 主机:代理IP地址
  • 端口:代理端口
  • 状态:1启用,0禁用

使用示例

/** @var \Symfony\Component\DomCrawler\Crawler $crawler */
$crawler = $container->get('modstore_rotating_proxy.manager')->crawlPage(
    'https://github.com/modstore/RotatingProxyBundle',
    'github',
    ['Referer' => 'https://www.google.com']
);

将返回一个Symfony dom crawler实例:https://symfony.com.cn/doc/current/components/dom_crawler.html

注意

为了确保请求不要过于相似,避免被当作机器人阻止,每个请求将设置一个随机的用户代理字符串。同时提供“Referer”字符串,该字符串应是一个可能的有机来源页面,也是很好的做法。

第二个参数是组名。请求将在组内轮换。通常对于特定域的所有请求,您会设置相同的组名。

测试命令

有一个测试命令来查看它的工作方式并测试您的请求。将输出页面正文。

php bin/console modstore_rotating_proxy:test

可选URL

php bin/console modstore_rotating_proxy:test --url='https://github.com/modstore/RotatingProxyBundle'

当省略url参数时,将向whatsmyip.org发送请求。

日志

所有请求的日志都存储在modstore_rotating_proxy_log表中。