• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Goutte\Client类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Goutte\Client的典型用法代码示例。如果您正苦于以下问题:PHP Client类的具体用法?PHP Client怎么用?PHP Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Client类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: testUserSeesPageTitle

 public function testUserSeesPageTitle()
 {
     $client = new Client();
     $crawler = $client->request('GET', 'http://localhost:8000/lists');
     $this->assertEquals(200, $client->getResponse()->getStatus());
     $this->assertCount(1, $crawler->filter('h1:contains("Lists")'));
 }
开发者ID:shk33,项目名称:todo-parrot,代码行数:7,代码来源:ListsTest.php


示例2: actionTrypostdata

 /**
  * simulate worldjournal ajax call to fetch content data
  */
 public function actionTrypostdata()
 {
     $hostname = 'www.wjlife.com';
     $optionVaules = ["relation" => "AND", "0" => ["relation" => "AND", "0" => ["key" => "wj_order_id"]]];
     //all help wanted
     $currentURL = "/cls_category/03-ny-help-wanted/";
     //temp page number
     $pno = 0;
     $queryObject = ["keyword" => "", "pagesize" => 40, "pno" => $pno, "optionVaules" => $optionVaules, "currentURL" => "http://" . $hostname . $currentURL, "currentCatId" => 327, "currentStateId" => 152];
     //language: chinese simplified
     $wjlang = "zh-cn";
     $requestUrl = "http://" . $hostname . "/wp-content/themes/wjlife/includes/classified-core.php?regions=state_ny&variant=" . $wjlang . "&t=" . time();
     // echo "start...\n";
     $client = new Client();
     $crawler = $client->request("POST", $requestUrl, $queryObject, [], ['HTTP_X-Requested-With' => 'XMLHttpRequest', 'contentType' => 'application/x-www-form-urlencoded;charset=utf-8']);
     $rowHtml = $crawler->html();
     // if you want to echo out with correct encoding, do `echo utf8_decode($rowHtml)`
     // echo utf8_decode($rowHtml);
     // echo "end...\n";
     $subCrawler = new Crawler();
     $subCrawler->addHtmlContent($rowHtml);
     $linkArray = $subCrawler->filter(".catDesc a")->each(function ($node, $index) {
         return $href = $node->attr('href');
     });
     print_r($linkArray);
 }
开发者ID:njuljsong,项目名称:scrapeAds,代码行数:29,代码来源:ScrapeController.php


示例3: 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


示例4: fetchDetails

 private function fetchDetails()
 {
     $url = 'https://www.twitter.com/' . $this->getAccountName();
     $client = new Client();
     $client->followRedirects();
     $crawler = $client->request('GET', $url);
     /**
      * @var Response $response
      */
     $response = $client->getResponse();
     if ($response->getStatus() != '200') {
         $this->setIsNotFound(true);
         return false;
     }
     // --
     if (stripos($response->getContent(), 'suspended')) {
         $this->setIsSuspended(true);
         return false;
     }
     // --
     $post_times = $crawler->filter('#stream-items-id li ._timestamp')->each(function (Crawler $node) {
         return $node->attr('data-time');
     });
     rsort($post_times);
     $last_post_time = $post_times[0];
     $hour_difference = round((time() - $last_post_time) / 60 / 60, 2);
     if ($hour_difference > 24) {
         // if last post was later than 24 hours
         $this->setDoesntHaveRecentPosts(true);
     }
 }
开发者ID:Gyvastis,项目名称:twitter-account-checker,代码行数:31,代码来源:AccountFilter.php


示例5: init

 /**
  * Initializing the plugin's behavior
  *
  * @return void
  */
 public function init()
 {
     $that = $this;
     $this->bot->onMessages('/^!php(doc)? (.*)/i', function (Event $event) use($that) {
         $request = $event->getRequest();
         $matches = $event->getMatches();
         $match = array_pop($matches);
         $client = new Client();
         $crawler = $client->request('GET', sprintf('http://www.php.net/%s', str_replace('_', '-', $match)));
         if ($crawler->filter('.refnamediv h1.refname')->count() !== 0) {
             $function = $crawler->filter('.refnamediv h1.refname')->first()->text();
             $description = $crawler->filter('.refnamediv span.dc-title')->first()->text();
             $version = $crawler->filter('.refnamediv p.verinfo')->first()->text();
             $synopsis = $crawler->filter('.methodsynopsis')->first()->text();
             $synopsis = preg_replace('/\\s+/', ' ', $synopsis);
             $synopsis = preg_replace('/(\\r\\n|\\n|\\r)/m', ' ', $synopsis);
             $synopsis = trim($synopsis);
             $event->addResponse(Response::msg($request->getSource(), sprintf('%s - %s %s', $function, $description, $version)));
             $event->addResponse(Response::msg($request->getSource(), sprintf('Synopsis: %s', $synopsis)));
         } else {
             $suggestion = $crawler->filter('#quickref_functions li a b')->first()->text();
             $event->addResponse(Response::msg($request->getSource(), sprintf('Could not find the requested PHP function. Did you mean: %s?', $suggestion)));
         }
     });
 }
开发者ID:frenck,项目名称:philip-plugins,代码行数:30,代码来源:PHPDocPlugin.php


示例6: traverseSingle

 /**
  * Crawl single URL
  * @param string $url
  * @param int    $depth
  */
 protected function traverseSingle($url, $depth)
 {
     try {
         $client = new Client();
         $client->followRedirects();
         $crawler = $client->request('GET', $url);
         $statusCode = $client->getResponse()->getStatus();
         $hash = $this->getPathFromUrl($url);
         $this->links[$hash]['status_code'] = $statusCode;
         if ($statusCode === 200) {
             $content_type = $client->getResponse()->getHeader('Content-Type');
             if (strpos($content_type, 'text/html') !== false) {
                 //traverse children in case the response in HTML document only
                 $this->extractTitleInfo($crawler, $hash);
                 $childLinks = array();
                 if (isset($this->links[$hash]['external_link']) === true && $this->links[$hash]['external_link'] === false) {
                     $childLinks = $this->extractLinksInfo($crawler, $hash);
                 }
                 $this->links[$hash]['visited'] = true;
                 $this->traverseChildren($childLinks, $depth - 1);
             }
         }
     } catch (CurlException $e) {
         $this->links[$url]['status_code'] = '404';
         $this->links[$url]['error_code'] = $e->getCode();
         $this->links[$url]['error_message'] = $e->getMessage();
     } catch (\Exception $e) {
         $this->links[$url]['status_code'] = '404';
         $this->links[$url]['error_code'] = $e->getCode();
         $this->links[$url]['error_message'] = $e->getMessage();
     }
 }
开发者ID:nunodotferreira,项目名称:arachnid,代码行数:37,代码来源:Crawler.php


示例7: loginToOrange

 /**
  * Call orange portal and submit credentials
  * @return [type]      [description]
  */
 protected function loginToOrange()
 {
     $config = $this->getHelperSet()->get('config');
     $this->outputMessage('Login to orange wifi ...');
     // Forge form submit as there is no button or input
     $parameters = array('username' => $config['login'], 'password' => $config['pass'], 'isCgu' => 'true', 'code' => 0, 'lang' => 'fr', 'auth' => 1, 'restrictedCode' => '', 'restrictedProfile' => 0, 'restrictedRealm' => '', 'originForm' => 'true', 'tab' => '1');
     try {
         $client = new Client();
         $crawler = $client->request('POST', 'https://hautdebitmobile.orange.fr:8443/home/wassup', $parameters);
     } catch (\Exception $e) {
         $this->outputError('Connection error : ' . $e->getMessage(), true);
         exit(1);
     }
     // If login is a success, we should have follow the redirect to orange home page
     if ($client->getRequest()->getUri() == 'http://www.orange.fr') {
         $this->outputMessage('Login success !');
     } else {
         $error_mssg = 'Login failed';
         $div_error = $crawler->filterXPath("//div[@id='loginFormWassupErrorMessage']");
         if ($div_error->count() == 1) {
             $error_mssg .= ' : ' . trim($div_error->text());
         }
         $this->outputError($error_mssg);
         // Output raw reponse if (-vv)
         if ($this->output->getVerbosity() > OutputInterface::VERBOSITY_VERBOSE) {
             echo $client->getResponse();
         }
         return 1;
     }
 }
开发者ID:zeliard91,项目名称:orange-hotspot,代码行数:34,代码来源:CheckCommand.php


示例8: show

 /**
  *
  * @api {get} /tarjeta/:id 1. Retorna la formación de una tarjeta Bip! según id 
  * @apiGroup Tarjeta
  * @apiName Show
  * @apiParam {Number} id número identificador de tarjeta bip.
  *
  * @apiSuccess {String} code Código de respuesta de la llamada
  * @apiSuccess {String} num-tarjeta  Número de la tarjeta.
  * @apiSuccess {String} estado  Detalle del estado del contrato de la tarjeta.
  * @apiSuccess {String} saldo  Saldo disponible en la tarjeta.
  * @apiSuccess {String} fecha-saldo  Feccha de la última carga.
  *
  * @apiSuccessExample Success-Response:
  *     HTTP/1.1 200 OK
  *     {
  *       "code": "John",
  *       "num-tarjeta": "15470725",
  *       "estado": "Contrato Activo",
  *       "saldo": "$2.530",
  *       "fecha-saldo": "10/09/2015 13:07",
  *     }
  * @apiError (Error 404) 404 Número de tarjeta ingresado sin saldo asociado.
  * @apiErrorExample {json} Error-Response:
  *     HTTP/1.1 404 Not Found
  *     {
  *       "code": 404,
  *       "num-tarjeta": "111",
  *       "message": "Esta tarjeta no tiene un saldo asociado"
  *     }
  * @apiError (Error 400)  400 Número de tarjeta ingresado con formato incorrecto.
  * @apiErrorExample {json} Error-Response:
  *     HTTP/1.1 404 Not Found
  *     {
  *       "code": 400,
  *       "num-tarjeta": "1547AAA725",
  *       "message": "El valor ingresado no es válido"
  *     }
  */
 public function show($id)
 {
     try {
         if (!is_numeric($id)) {
             $statusCode = 404;
             $response = ["code" => 404, "num-tarjeta" => $id, "message" => "El valor ingresado no es válido"];
             return new JsonResponse($response, $statusCode);
         }
         $client = new Client();
         $crawler = $client->request('POST', 'http://pocae.tstgo.cl/PortalCAE-WAR-MODULE/SesionPortalServlet?accion=6&NumDistribuidor=99&NomUsuario=usuInternet&NomHost=AFT&NomDominio=aft.cl&Trx=&RutUsuario=0&NumTarjeta=' . $id . '&bloqueable=');
         $nodeValues = $crawler->filter('td.verdanabold-ckc')->each(function ($node, $i) {
             return $node->text();
         });
         if (count($nodeValues) > 7) {
             $statusCode = 200;
             $response = ["code" => 200, "num-tarjeta" => $id, "estado" => $nodeValues[3], "saldo" => $nodeValues[5], "fecha-saldo" => $nodeValues[7]];
         } else {
             $statusCode = 404;
             $response = ["code" => 404, "num-tarjeta" => $id, "message" => "Esta tarjeta no tiene un saldo asociado"];
         }
         return new JsonResponse($response, $statusCode);
     } catch (Exception $e) {
         $statusCode = 500;
         $response = ["code" => 500, "num-tarjeta" => $id, "message" => "Error del servidor"];
         return new JsonResponse(null, $statusCode);
     }
 }
开发者ID:kinalef,项目名称:saldo-bip,代码行数:66,代码来源:TarjetaController.php


示例9: update

 function update()
 {
     $client = new Client();
     $url = 'http://no.wikipedia.org/wiki/Norges_kommuner';
     $crawler = $client->request('GET', $url);
     $entries = array();
     $i = 0;
     $crawler->filter('div#bodyContent table.wikitable tr')->each(function ($node) use(&$i, &$entries) {
         if ($i > 0) {
             $ft = $node->filter('td')->eq(4)->html();
             $ft = preg_replace('/<(.*)>/', '', $ft);
             $ft = preg_replace('/[^0-9]/', '', $ft);
             $item = array();
             $item['knr'] = $node->filter('td')->eq(0)->text();
             $item['kommune.navn'] = $node->filter('td')->eq(1)->text();
             $item['kommune.admsenter'] = $node->filter('td')->eq(2)->text();
             $item['kommune.fylke'] = $node->filter('td')->eq(3)->text();
             // $item['kommune.folketall'] = urldecode($node->filter('td')->eq(4)->text());
             $item['kommune.folketall'] = intval($ft, 10);
             $item['kommune.areal'] = $node->filter('td')->eq(5)->text();
             $item['kommune.maalform'] = $node->filter('td')->eq(8)->text();
             $item['kommune.iconurl'] = 'http:' . $node->filter('td')->eq(7)->filter('img')->attr('src');
             // echo "Item " . $i . "\n";
             // print_r($item);
             $entries[] = $item;
         }
         $i++;
     });
     file_put_contents($this->cacheFile, json_encode($entries));
 }
开发者ID:NIIF,项目名称:DiscoJuice-Backend,代码行数:30,代码来源:KommuneHelper.php


示例10: testAddRating_withGet_HasEmptyForm

 public function testAddRating_withGet_HasEmptyForm()
 {
     $client = new Client();
     $response = $client->request('GET', 'http://localhost/workspace/cursoPHPUnit/gamebook/web/add-rating.php?game=1');
     $this->assertCount(1, $response->filter('form'));
     $this->assertEquals("", $response->filter('form input[name=score]')->attr("value"));
 }
开发者ID:ivanknow,项目名称:exemplophpunit,代码行数:7,代码来源:GameControllerTest.php


示例11: crawl

 /**
  * return response code when crawling a given url
  * @param $url
  * @return mixed
  */
 function crawl($url)
 {
     $client = new Client();
     $client->request('GET', $url);
     $response_code = $client->getResponse()->getStatus();
     return $response_code;
 }
开发者ID:tcs-udemy,项目名称:introduction-to-unit-testing,代码行数:12,代码来源:CrawlTrait.php


示例12: obtener_grupo

function obtener_grupo($url)
{
    $client = new Client();
    $crawler = $client->request('GET', $url);
    $datos_grupo = obtener_datos_grupo($crawler);
    guardar_grupo($datos_grupo);
}
开发者ID:ndecia91,项目名称:-Webir-Laboratorio,代码行数:7,代码来源:obtener_grupo.php


示例13: getStockPrice

 /**
  * 現在の株価を取得する
  *
  * @param 整数値 $code 取得する株価コード
  * @return bool true 成功
  */
 public function getStockPrice($code)
 {
     try {
         $client = new Client();
         $crawler = $client->request('GET', "http://stocks.finance.yahoo.co.jp/stocks/detail/?code={$code}.T");
         // 前日終値、始値、高値、安値を取得する
         $array = $crawler->filter('dd')->each(function ($element) {
             $array = $element->filter('strong')->each(function ($element) {
                 return $element->text();
             });
             // Debug::logPrintR($array);
             return count($array) > 0 ? $array[0] : null;
         });
         // Debug::logPrintR($array);
         // $array の要素は以下の様になっている
         // [2] 前日終値
         // [3] 始値
         // [4] 高値
         // [5] 安値
         if (count($array) >= 6) {
             $this->beforeClosingPrice = $this->removeComma($array[2]);
             $this->openingPrice = $this->removeComma($array[3]);
             $this->highPrice = $this->removeComma($array[4]);
             $this->lowPrice = $this->removeComma($array[5]);
         }
         // 現在値を取得する
         $element = $crawler->filter('td.stoksPrice')->last();
         $this->nowPrice = $this->removeComma($element->text());
     } catch (exception $e) {
         // Debug::logPrintR($e);
         return false;
     }
     return true;
 }
开发者ID:KittenEar,项目名称:stock,代码行数:40,代码来源:StockCrawler.php


示例14: fetchTemplate

 protected function fetchTemplate()
 {
     $goutte = new Client();
     $crawler = $goutte->request('GET', 'https://www.drupal.org/node/2373483');
     $beta_evaluation = (string) $crawler->filter('div.codeblock code')->getNode(0)->nodeValue;
     return $beta_evaluation;
 }
开发者ID:joelpittet,项目名称:dopatchutils,代码行数:7,代码来源:BetaEval.php


示例15: getHoje

 public static function getHoje()
 {
     $nomes = ["Cantareira", "Guarapiranga", "Alto Cotia", "Alto Tietê", "Rio Claro", "Rio Grande"];
     $client = new Client();
     $crawler = $client->request('GET', 'http://www.apolo11.com/reservatorios.php?step=d');
     $tables = $crawler->filter("font[face='arial']");
     $data = $crawler->filter("font[face='verdana']");
     $obj = new stdClass();
     $obj->data = $data->eq(10)->text() . "/" . date('y');
     $obj->niveis = array();
     $tmp = array();
     for ($i = 0; $i < 6; $i++) {
         $nivel = new stdClass();
         $nivel->nome = $nomes[$i];
         $nivel->hoje = $tables->eq($i * 9 + 16)->text();
         $nivel->ontem = $tables->eq($i * 9 + 15)->text();
         $nivel->chuva = preg_replace("/[^0-9,.]/", "", $tables->eq(5 - $i)->text());
         $tmp[] = $nivel;
     }
     $obj->niveis[0] = $tmp[0];
     $obj->niveis[1] = $tmp[3];
     $obj->niveis[2] = $tmp[1];
     $obj->niveis[3] = $tmp[2];
     $obj->niveis[4] = $tmp[5];
     $obj->niveis[5] = $tmp[4];
     return $obj;
 }
开发者ID:akaFTS,项目名称:cantareiraBot,代码行数:27,代码来源:Mananciais.php


示例16: __construct

 public function __construct($url)
 {
     $client = new Client();
     $crawler = $client->request('GET', $url);
     $this->content = $crawler->filterXPath("//div[@class='tekstas']");
     $this->scrape();
 }
开发者ID:vjaykoogu,项目名称:IcyFood,代码行数:7,代码来源:ScrapeService.php


示例17: scrape

 /**
  * @param string $url
  * @return ProductList $list
  */
 public function scrape($url)
 {
     $productList = new ProductList();
     $client = new Client();
     $crawler = $client->request('GET', $url);
     $crawler->filterXPath('//*[@class="productInfo"]/h3/a')->each(function ($node) use($productList, $client) {
         /** @var Crawler $node */
         $product = new Product();
         $link = $node->link();
         $subPage = $client->click($link);
         $subPage->filter('.productTitleDescriptionContainer > h1')->first()->each(function ($node) use($product) {
             /** @var Crawler $node */
             $product->title = trim($node->text());
         });
         $subPage->filter('.pricePerUnit')->each(function ($node) use($product) {
             /** @var Crawler $node */
             $product->unitPrice = $node->text();
         });
         $product->size = sprintf("%.2f", strlen($subPage->html()) / 1024);
         $subPage->filter('.pricePerUnit')->each(function ($node) use($product) {
             /** @var Crawler $node */
             preg_match("/[\\d\\.]+/", $node->text(), $price);
             $product->unitPrice = $price[0];
         });
         $subPage->filter('htmlcontent > div')->first()->each(function ($node) use($product) {
             /** @var Crawler $node */
             $product->description = trim($node->text());
         });
         $productList->addProduct($product);
     });
     return $productList;
 }
开发者ID:sbscrape,项目名称:consoleapp,代码行数:36,代码来源:GoutteScraper.php


示例18: index

 /**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     for ($i = 68; $i <= 78; $i++) {
         //$photos=Image::paginate(50);
         $client = new Client();
         $baseURL = 'http://www.cutecatgifs.com/page';
         $urlEndpoint = '/' . $i++;
         $crawler = $client->request('GET', $baseURL . $urlEndpoint);
         $photos = $crawler->filter('img.alignnone')->extract(array('src', 'alt'));
         foreach ($photos as $photo) {
             $url = $photo[0];
             $title = $photo[1];
             $extension = pathinfo($url, PATHINFO_EXTENSION);
             $filename = str_random(4) . '-' . str_slug($title) . '.' . $extension;
             // get file content from url and save in directory
             $file = file_get_contents($url);
             $save_file = file_put_contents('uploads/' . $filename, $file);
             // Create record in database
             $image = new \App\Image();
             $image->name = $photo[1];
             $image->url = $filename;
             $image->user_id = 1;
             $image->description = $photo[1];
             $image->save();
         }
     }
 }
开发者ID:Gadurp1,项目名称:KD-2,代码行数:32,代码来源:WebTrackController.php


示例19: getDataURL

 /**
  * @param $url
  * @return Crawler
  */
 function getDataURL($url)
 {
     $client = new Client();
     $jsonURL = AlloSurfGetData::getJsonUrl($url);
     $crawler = $client->request('GET', $jsonURL);
     return $crawler;
 }
开发者ID:lapoiz,项目名称:WindServer2,代码行数:11,代码来源:AlloSurfGetData.php


示例20: devtips_get

function devtips_get($url)
{
    $tip = new DevTip(array("url" => $url));
    $client = new Client();
    $crawler = $client->request('GET', $url);
    $crawler->filter('div.dt-content')->each(function ($node) use(&$tip) {
        $html = trim($node->html());
        // add line breaks
        $html = str_replace("><", ">\n<", $html);
        // remove aside
        $pos = strpos($html, "<aside");
        if ($pos !== false) {
            $html = substr($html, 0, $pos);
        }
        // convert <p>'s to just line breaks
        $html = str_replace("<p>", "\n", $html);
        $html = str_replace("</p>", "\n", $html);
        $tip->set('content', $html);
    });
    $crawler->filter('h3')->each(function ($node) use(&$tip) {
        $tip->set('title', $node->text());
    });
    $sources = $crawler->filter('div.dt-content *[src]')->extract(array('src'));
    $tip->set('assets', $sources);
    return $tip;
}
开发者ID:niallobrien,项目名称:WebFundamentals,代码行数:26,代码来源:devtips.php



注:本文中的Goutte\Client类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Facades\Binput类代码示例发布时间:2022-05-23
下一篇:
PHP Model\Project类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap