本文整理汇总了PHP中Symfony\Component\DomCrawler\Crawler::selectLink方法的典型用法代码示例。如果您正苦于以下问题:PHP Crawler::selectLink方法的具体用法?PHP Crawler::selectLink怎么用?PHP Crawler::selectLink使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DomCrawler\Crawler
的用法示例。
在下文中一共展示了Crawler::selectLink方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getDetails
/**
* Gets the details page.
*
* @return Crawler
* @todo Refactor this as it is not possible to mock currently
*/
private function getDetails()
{
if (is_null($this->details)) {
$url = $this->crawler->selectLink($this->getTitle())->link()->getUri();
$scraper = new Scraper();
$this->details = $scraper->fetch($url);
$this->length = $scraper->getResponseSize();
}
return $this->details;
}
示例2: dontSeeLink
public function dontSeeLink($text, $url = null)
{
$links = $this->crawler->selectLink($text);
if ($url) {
$links = $links->filterXPath(sprintf('.//a[contains(@href, %s)]', Crawler::xpathLiteral($url)));
}
$this->assertDomNotContains($links, 'a');
}
示例3: dontSeeLink
public function dontSeeLink($text, $url = null)
{
$links = $this->crawler->selectLink($this->escape($text));
if (!$url) {
\PHPUnit_Framework_Assert::assertEquals(0, $links->count(), "'{$text}' on page");
}
$links->filterXPath(sprintf('descendant-or-self::a[contains(@href, "%s")]', Crawler::xpathLiteral(' ' . $this->escape($url) . ' ')));
\PHPUnit_Framework_Assert::assertEquals(0, $links->count());
}
示例4: click
/**
* Click a link with the given body, name, or ID attribute.
*
* @param string $name
* @return $this
*/
protected function click($name)
{
$link = $this->crawler->selectLink($name);
if (!count($link)) {
$link = $this->filterByNameOrId($name, 'a');
if (!count($link)) {
throw new InvalidArgumentException("Could not find a link with a body, name, or ID attribute of [{$name}].");
}
}
$this->visit($link->link()->getUri());
return $this;
}
示例5: iClickTheLink
/**
* @When /^I click the ([^"]*) link in the e-?mail$/
*/
public function iClickTheLink($linkText)
{
if (empty($this->email)) {
throw new \Exception('No email to click through from.');
}
$crawler = new Crawler();
$crawler->addHtmlContent($this->email['htmlContent']['htmlBody']);
try {
$href = $crawler->selectLink($linkText)->attr('href');
} catch (\InvalidArgumentException $e) {
throw new \Exception("No link with text '{$linkText}' found in email.");
}
$this->getSession()->visit($href);
}
示例6: doAlunoLogin
/**
* Does login with ID and password.
**/
public function doAlunoLogin()
{
// get csrf token
$this->crawler = $this->client->request('GET', $this->endpoint);
$token = $this->crawler->filter('input[name="csrfmiddlewaretoken"]');
$token = $token->attr('value');
// get form and submit
$form = $this->crawler->selectButton('Acessar')->form();
$this->crawler = $this->client->submit($form, ['username' => $this->username, 'password' => $this->password, 'csrfmiddlewaretoken' => $token]);
// get matricula number
$meusdados_link = $this->crawler->selectLink('Meus Dados')->link()->getUri();
$link_parts = explode('/', $meusdados_link);
$this->matricula = $link_parts[5];
}
示例7: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var FormatterHelper $formatter */
$formatter = $this->getHelper('formatter');
$html = file_get_contents('http://spb.hh.ru/search/vacancy?text=php&clusters=true&enable_snippets=true');
$crawler = new Crawler($html, 'http://spb.hh.ru/search/vacancy?text=php&clusters=true&enable_snippets=true');
$output->writeln($formatter->formatBlock('Vacancies', 'question', true));
$crawler->filterXPath(CssSelector::toXPath('body a.search-result-item__name'))->each(function (Crawler $node) use($output) {
$output->writeln(sprintf('<comment>%s</comment>', $node->text()));
});
$data = $crawler->filter('body a.search-result-item__name')->extract(['_text', 'class']);
print_r($data[0]);
$output->writeln($formatter->formatBlock('Link test', 'question', true));
$link = $crawler->selectLink('PHP developer')->link();
$output->writeln($link->getUri());
$crawler = new Crawler(file_get_contents('http://spb.hh.ru/login'), 'http://spb.hh.ru/login');
$output->writeln($formatter->formatBlock('Form test', 'question', true));
$form = $crawler->selectButton('Войти')->form(['username' => 'name', 'password' => 'pass']);
$output->writeln($form->getUri());
$form['remember']->tick();
$output->writeln(print_r($form->getPhpValues()));
}
开发者ID:GrizliK1988,项目名称:symfony-certification-prepare-project,代码行数:22,代码来源:DomCrawlerHHTestCommand.php
示例8: testSelectLinkAndLinkFiltered
public function testSelectLinkAndLinkFiltered()
{
$html = <<<HTML
<!DOCTYPE html>
<html lang="en">
<body>
<div id="action">
<a href="/index.php?r=site/login">Login</a>
</div>
<form id="login-form" action="/index.php?r=site/login" method="post">
<button type="submit">Submit</button>
</form>
</body>
</html>
HTML;
$crawler = new Crawler($html);
$filtered = $crawler->filterXPath("descendant-or-self::*[@id = 'login-form']");
$this->assertCount(0, $filtered->selectLink('Login'));
$this->assertCount(1, $filtered->selectButton('Submit'));
$filtered = $crawler->filterXPath("descendant-or-self::*[@id = 'action']");
$this->assertCount(1, $filtered->selectLink('Login'));
$this->assertCount(0, $filtered->selectButton('Submit'));
$this->assertCount(1, $crawler->selectLink('Login')->selectLink('Login'));
$this->assertCount(1, $crawler->selectButton('Submit')->selectButton('Submit'));
}
示例9: test_getLink
public function test_getLink()
{
$link = $this->decorator->getLink();
$crawler = new Crawler($link);
$this->assertEquals($this->decorator->getUrl(), $crawler->selectLink("Term 1")->attr('href'));
}
示例10: getNextLink
/**
* @param SymfonyCrawler $crawler
* @return \Symfony\Component\DomCrawler\Link|null
*/
protected function getNextLink(SymfonyCrawler $crawler)
{
$linkNode = $crawler->selectLink('След');
return count($linkNode) ? $linkNode->link() : null;
}
示例11: Crawler
function test_Link()
{
$link = $this->decorator->link;
$crawler = new Crawler($link);
$this->assertEquals($this->decorator->url, $crawler->selectLink('Post title 1')->attr('href'));
}
示例12: pagination
/**
* @param Crawler $crawler
* @return boolean|Crawler
* TODO: Поиск записей по всем доступным страницам.
*/
protected function pagination(Crawler $crawler)
{
$nextPageCrawler = $crawler->selectLink('След.');
if ($nextPageCrawler && $nextPageCrawler->getNode(0) && false === mb_stripos($nextPageCrawler->getNode(0)->getAttribute('class'), 'ui-disabled', null, 'UTF-8')) {
return self::$client->click($nextPageCrawler->link());
}
return false;
}
示例13: iGoToInTheEmail
/**
* Assumes an email has been identified by a previous step,
* e.g. through 'Given there should be an email to "test@test.com"'.
*
* @When /^I click on the "([^"]*)" link in the email"$/
*/
public function iGoToInTheEmail($linkSelector)
{
if (!$this->lastMatchedEmail) {
throw new \LogicException('No matched email found from previous step');
}
$match = $this->lastMatchedEmail;
$crawler = new Crawler($match->Content);
$linkEl = $crawler->selectLink($linkSelector);
assertNotNull($linkEl);
$link = $linkEl->attr('href');
assertNotNull($link);
return new Step\When(sprintf('I go to "%s"', $link));
}
示例14: clickLink
/**
* Clicks a link
*
* @param Crawler $crawler
* @param string $where Translation key of the link text
*
* @return Crawler
*/
public static function clickLink(Crawler $crawler, $where)
{
$link = $crawler->selectLink(self::$translator->trans($where));
return self::$client->click($link->link());
}