modstore / rotating-proxy-bundle
该软件包的最新版本(dev-master)没有可用的许可信息。
Symfony的轮换代理包。
dev-master
2019-01-03 00:43 UTC
Requires
- php: >=7.1.0
- campo/random-user-agent: ^1.3
- doctrine/common: ~2.0
- fabpot/goutte: ^3.1
- guzzlehttp/guzzle: ~6.0
- symfony/framework-bundle: ~3.0
Requires (Dev)
- liip/functional-test-bundle: 1.2.2|~1.3
- phpunit/phpunit: 4.6.*
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表中。