本文整理汇总了PHP中Goutte\Client类的典型用法代码示例。如果您正苦于以下问题:PHP Client类的具体用法?PHP Client怎么用?PHP Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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")'));
}
示例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);
}
示例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);
}
}
示例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)));
}
});
}
示例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();
}
}
示例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;
}
}
示例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);
}
}
示例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));
}
示例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"));
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}