本文整理汇总了PHP中Goutte\Client::getHistory方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::getHistory方法的具体用法?PHP Client::getHistory怎么用?PHP Client::getHistory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Goutte\Client
的用法示例。
在下文中一共展示了Client::getHistory方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ensureLoggedIn
public function ensureLoggedIn()
{
$crawler = $this->client->request('GET', '/user/login');
/** @var Response $response */
$response = $this->client->getResponse();
if ($response->getStatus() < 200 && $response->getStatus() >= 300) {
return;
}
$loginForm = $crawler->filter('#loginPageForm')->form();
$this->client->submit($loginForm, ['username' => $this->username, 'password' => $this->password]);
if (strpos($this->client->getHistory()->current()->getUri(), 'account') === FALSE) {
throw new \PHPUnit_Framework_Exception("Should be logged in, but is not.");
}
}
示例2: execute
/**
* @param InputInterface $input The input instance
* @param OutputInterface $output The output instance
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$pages = 25;
$page = 1;
$output->writeln('<info>Beginning Google crawl</info>');
$query = new QueryString(array('q' => 'site:drupalcode.org "composer.json" "drupal-module"'));
$url = 'http://www.google.com/search?' . $query;
// Load page 1
$client = new Client();
$crawler = $client->request('GET', $url);
$repos = array();
// Crawl through search pages.
do {
$current = $client->getHistory()->current()->getUri();
$output->writeln('<info>Crawling:</info> ' . $current);
// Use a CSS filter to select only the result links:
$links = $crawler->filter('li h3 a');
// Search the links for the domain:
foreach ($links as $index => $link) {
$href = $link->getAttribute('href');
$query = QueryString::fromString(parse_url($href, PHP_URL_QUERY));
$url = $query->get('q');
// Match pages with composer.json in root.
if (preg_match('/^http:\\/\\/drupalcode.org.+\\.git\\/.+\\/composer.json$/i', $url)) {
// Strip to git url and rewrite to drupalcode.org then store unique matches.
$matches = array();
preg_match('/^http:\\/\\/drupalcode.org.+\\.git/i', $url, $matches);
$repo = str_replace('http://drupalcode.org/', 'http://git.drupal.org/', $matches[0]);
$repos[$repo] = null;
$output->writeln('<info>Found:</info> ' . $repo);
}
}
// Turn the page.
$page++;
$node = $crawler->filter('table#nav')->selectLink($page);
if ($node->count()) {
$crawler = $client->click($node->link());
} else {
break;
}
} while ($page < $pages);
$path = getcwd() . '/satis.json';
$file = new JsonFile($path);
$data = $file->read();
foreach ($data['repositories'] as $file_repo) {
$repos[$file_repo['url']] = null;
}
$repos = array_keys($repos);
sort($repos);
$data['repositories'] = array();
foreach ($repos as $repo) {
$data['repositories'][] = array('url' => $repo, 'type' => 'vcs');
}
$file->write((array) $data);
}
示例3: run
/**
* @param $testId
* @param int $operationId
* @param array $testData
* @return array
*/
public function run($testId, $operationId = 0, $testData = [])
{
//$opData = $testData['operations'][$operationId];
$orderId = $testData['orderId'];
// Log in
$crawler = $this->client->request('GET', $this->host . '/user/login');
$loginFormNode = $crawler->filter('#loginPageForm');
$loginForm = $loginFormNode->form();
$this->client->submit($loginForm, ['username' => $this->username, 'password' => $this->password]);
// Find a page with transaction form and submit it (override in subclasses)
$crawler = $this->submitTransactionForm($orderId);
//var_dump($this->client->getHistory(), parse_url($this->client->getHistory()->current()->getUri())); exit;
// Go home
$homeForm = $crawler->filter('form')->first()->form();
$result = ['ACTION' => $homeForm->get('ACTION')->getValue(), 'RC' => $homeForm->get('RC')->getValue(), 'TRTYPE' => $homeForm->get('TRTYPE')->getValue(), 'RRN' => $homeForm->get('RRN')->getValue(), 'operation' => $operationId, 'test' => $testId, 'ORDER' => $homeForm->get('ORDER')->getValue(), 'date' => date('m/d/Y')];
$this->client->submit($homeForm);
ob_start();
var_dump($this->client->getHistory());
$result['history'] = ob_get_clean();
return $result;
}
示例4: getCategoryById
/**
* @param int $categoryId
* @return Category
*/
public function getCategoryById($categoryId)
{
$url = 'http://www.tunisianet.com.tn/' . $categoryId . '-';
$crawler = $this->client->request('GET', $url);
$url = $this->client->getHistory()->current()->getUri();
$title = $crawler->filter('title')->text();
$products = $crawler->filter('#produit_liste_main .ajax_block_product')->each(function (Crawler $node) {
$title = $node->filter('.center_block > h2 > a')->text();
$id = intval($node->filter("input[id^='hit_id']")->attr('value'));
$reference = $node->filter("input[id^='hit_ref']")->attr('value');
$description = $node->filter('.center_block > .product_desc > a')->text();
$priceTag = $node->filter('.price')->text();
$price = floatval(str_replace(',', '.', $priceTag));
$available = $node->filter('#produit_liste_prix > div:nth-child(2)')->attr('class') === 'en_stock';
$url = $node->filter('.center_block > h2 > a')->attr('href');
$product = new Product($id, $title, $reference, $description, $price, $available, $url);
return $product;
});
$category = new Category($categoryId, $title, $url, $products);
return $category;
}