本文整理汇总了PHP中Goutte\Client::setClient方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::setClient方法的具体用法?PHP Client::setClient怎么用?PHP Client::setClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Goutte\Client
的用法示例。
在下文中一共展示了Client::setClient方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setProxy
/**
* {@inheritdoc}
* @param Proxy $proxy
*
* @return mixed|void
* @throws \Exception
*/
public function setProxy(Proxy $proxy)
{
$sessionName = md5($proxy->getUrl());
$this->browser->resetSessions();
if ($this->browser->hasSession($sessionName)) {
$this->browser->setDefaultSessionName($sessionName);
return;
}
$driver = $this->browser->getSession()->getDriver();
switch (get_class($driver)) {
case 'Behat\\Mink\\Driver\\GoutteDriver':
/* @var $driver GoutteDriver */
$client = new Client();
$guzzle = $client->getClient();
$client->setClient($guzzle);
$guzzle->setDefaultOption('proxy', $proxy->getUrl());
$goutteDriver = new GoutteDriver($client);
$this->browser->registerSession($sessionName, new Session($goutteDriver));
$this->browser->setDefaultSessionName($sessionName);
break;
default:
throw new \Exception('Error : Proxy configuration is not implemented for class ' . get_class($driver) . '');
}
}
示例2: setUpClient
private function setUpClient()
{
$this->client = new Client();
$this->client->setHeader('User-Agent', $this->user_agent);
$this->client->setHeader('Accept-Language', 'en-gb');
$this->client->setClient(new \GuzzleHttp\Client(['allow_redirects' => false, 'cookies' => true, 'verify' => false, 'proxy' => ['http' => $this->proxy]]));
}
示例3: setupClient
public function setupClient($clientClass, $httpClientClass)
{
if (is_null($this->client)) {
$this->client = new $clientClass();
/**
* @var \GuzzleHttp\Client $httpClientClass
*/
$httpClient = new $httpClientClass([RequestOptions::VERIFY => false, RequestOptions::TIMEOUT => 1800]);
$this->client->setClient($httpClient);
}
}
示例4: __construct
/**
* Construct function.
*
* @param string $username Matricula
* @param string $password User's password
* @param bool $is_access_key Whether use access code
*/
public function __construct($username = null, $password = null, $is_access_key = false)
{
if ($username && $password) {
$this->username = $username;
$this->password = $password;
$this->is_access_key = $is_access_key;
}
// Goutte client
$this->client = new Client();
// Create and use a guzzle client instance that will time out after 10 seconds
$guzzle_client = new \GuzzleHttp\Client(['timeout' => 10, 'connect_timeout' => 10]);
$this->client->setClient($guzzle_client);
}
示例5: useProxyIfAvailable
private function useProxyIfAvailable(Client $client)
{
if (defined('SS_OUTBOUND_PROXY') && defined('SS_OUTBOUND_PROXY_PORT')) {
$guzzleClient = new GuzzleClient('', array('request.options' => array('proxy' => 'tcp://' . SS_OUTBOUND_PROXY . ':' . SS_OUTBOUND_PROXY_PORT)));
$client->setClient($guzzleClient);
}
}
开发者ID:helpfulrobot,项目名称:deptinternalaffairsnz-silverstripe-navigation-scraper,代码行数:7,代码来源:NavigationScraperService.php
示例6: setupClient
public function setupClient()
{
$clientClass = $this->clientClass;
$this->httpClient = new $clientClass();
$httpClientClass = $this->httpClientClass;
$httpClient = new $httpClientClass([RequestOptions::VERIFY => false, RequestOptions::TIMEOUT => 1800]);
$this->httpClient->setClient($httpClient);
}
示例7: getClient
/**
* @return GouteClient
*/
public function getClient()
{
if (!$this->client) {
$this->client = new GouteClient();
$this->client->setClient(new GuzzleClient(['verify' => false]));
}
return $this->client;
}
示例8: testImage
public function testImage()
{
$client = new Client();
$client->setClient($this->getGuzzle(require __DIR__ . '/response/SoundCloud.php'));
$ripple = new Ripple(self::URL_TRACK);
$ripple->request($client);
$this->assertSame('soundcloud_thumbnail.jpg', $ripple->image());
}
示例9: testEmbed
/**
* @param string $file
* @param string $url
* @param string $embed
* @dataProvider embedProvider
*/
public function testEmbed($file, $url, $embed)
{
$client = new Client();
$client->setClient($this->getGuzzle(require __DIR__ . "/response/{$file}.php"));
$ripple = new Ripple($url);
$ripple->request($client);
$this->assertSame($embed, $ripple->embed());
}
示例10: testImage
public function testImage()
{
$client = new Client();
$client->setClient($this->getGuzzle(require __DIR__ . '/response/Vimeo.php'));
$ripple = new Ripple(self::URL_TRACK . static::id());
$ripple->request($client);
$this->assertSame('vimeo_thumbnail.jpg', $ripple->image());
}
示例11: actionIndex
public function actionIndex()
{
/** @var $entity RivegaucheLink */
$entity = new RivegaucheLink();
$offset = 0;
do {
$links = $entity->getLinks($offset, 5);
if (!empty($links)) {
foreach ($links as $link) {
\Yii::info(sprintf('Обрабатываем: %s ', $link['link']), 'cron');
$client = new Client();
$guzzle = $client->getClient();
$client->getClient()->setDefaultOption('config/curl/' . CURLOPT_PROXY, 'http://141.101.118.147:80');
//$client->getClient()->setDefaultOption('config/curl/'.CURLOPT_TIMEOUT, 10);
$client->getClient()->setDefaultOption('config/curl/' . CURLOPT_CONNECTTIMEOUT, 10);
$client->setClient($guzzle);
/*$guzzle = $client->getClient();
$guzzle->setDefaultOption('timeout', 10);
$client->getClient()->setDefaultOption('config/curl/'.CURLOPT_TIMEOUT_MS, 100);
$client->getClient()->setDefaultOption('config/curl/'.CURLOPT_CONNECTTIMEOUT, 5);
$client->getClient()->setDefaultOption('config/curl/'.CURLOPT_RETURNTRANSFER, true);
$client->setClient($guzzle);*/
$crawler = $client->request('GET', $link['link']);
\Yii::info(sprintf('Извлекаем тело: %s ', $link['link']), 'cron');
$head = $this->getHtml($crawler, true);
\Yii::info(sprintf('HEAD тело: %s ', $link['link']), 'cron');
if (!empty($head['links'])) {
foreach ($head['links'] as $l) {
$crawler = $client->request('GET', $l);
$subHead = $this->getHtml($crawler, false);
$subHead['link'] = $l;
$this->saveResult($subHead, $link);
}
}
if (empty($head['title'])) {
$head = $this->getPromoHTML($crawler, true);
}
if (empty($head['title'])) {
$head = $this->getPromo2HTML($crawler, true);
}
$head['link'] = $link['link'];
$this->saveResult($head, $link);
unset($node);
unset($subNode);
unset($head);
}
$z = 1;
$offset += 5;
unset($links);
unset($client);
} else {
$z = 0;
}
} while ($z > 0);
return 0;
}
示例12: cinemex
public function cinemex()
{
$client = new Client();
//$client->getClient()->setDefaultOption('config/curl/' . CURLOPT_SSL_VERIFYPEER, false);
$guzzleClient = new \GuzzleHttp\Client(array('curl' => array(CURLOPT_SSL_VERIFYPEER => false)));
$client->setClient($guzzleClient);
$crawler = $client->request('POST', 'http://www.cinepolis.com/pelicula/deadpool');
dd($crawler->html());
}
示例13: setUp
public function setUp()
{
$this->guzzleMockPlugin = new MockPlugin();
$guzzleClient = new GuzzleClient();
$guzzleClient->addSubscriber($this->guzzleMockPlugin);
$goutte = new Client();
$goutte->setClient($guzzleClient);
$this->api = new Api($goutte);
}
示例14: scrapeIcons
private function scrapeIcons()
{
$guzzleClient = new \GuzzleHttp\Client(array('timeout' => $this->timeout, 'verify' => false));
$client = new Client();
$client->setClient($guzzleClient);
$crawler = $client->request('GET', $this->url);
$link_tags = $crawler->filter("link");
$icons = array();
$url_array =& $this->url_array;
$startsWidth = function ($haystack, $needle) {
return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== false;
};
$link_tags->each(function (Crawler $crawler) use(&$icons, &$url_array, &$startsWidth) {
$node = $crawler->getNode(0);
$has_attribute_rel = $node->hasAttribute("rel");
$has_attribute_href = $node->hasAttribute("href");
$icon = false;
if ($has_attribute_rel && $has_attribute_href) {
$attribute_rel = $node->getAttribute("rel");
$attribute_href = $node->getAttribute("href");
$has_attribute_sizes = $node->hasAttribute("sizes");
switch ($attribute_rel) {
case IconType::APPLE_TOUCH:
case IconType::SHORTCUT_ICON:
case IconType::FAVICON:
case IconType::APPLE_TOUCH_PRECOMPOSED:
case IconType::ANDROID_TOUCH:
$attribute_href_has_no_scheme = $startsWidth($attribute_href, "//");
$href = filter_var($attribute_href, FILTER_VALIDATE_URL) || $attribute_href_has_no_scheme ? $attribute_href : $url_array["scheme"] . "://" . $url_array["host"] . $attribute_href;
if ($has_attribute_sizes) {
$sizes = strtolower($node->getAttribute("sizes"));
$sizes_array = explode("x", $sizes);
$size_width = false;
$size_height = false;
if ($sizes_array && sizeof($sizes_array) == 2) {
$size_width = intval($sizes_array[0]);
$size_height = intval($sizes_array[1]);
}
$buffer = file_get_contents($attribute_href_has_no_scheme ? "http:" . $href : $href);
$f = finfo_open();
$mime_type = finfo_buffer($f, $buffer, FILEINFO_MIME_TYPE);
$b64image = "data:{$mime_type};base64," . base64_encode($buffer);
$icon = new Icon($attribute_rel, $href, $sizes, $size_width, $size_height, $b64image);
} else {
$icon = new Icon($attribute_rel, $href);
}
break;
}
}
if ($icon) {
array_push($icons, $icon);
}
});
$this->icons = $icons;
}
示例15: testGetProductDetails
public function testGetProductDetails()
{
$expected = ["size" => "37.25kb", "title" => "Sainsbury's Avocado Ripe & Ready XL Loose 300g", "unit_price" => '1.50', "description" => "Avocados"];
$responses = [new GuzzleResponse(200, [], $this->htmlSainsburyProduct)];
$guzzle = $this->getGuzzle($responses);
$client = new Client();
$client->setClient($guzzle);
$scraper = new Scraper($client);
$product = $scraper->getProductDetails('www.dummmy.com');
$this->assertEquals($expected, $product);
}