D
D
den4eg112015-11-24 19:24:05
Node.js
den4eg11, 2015-11-24 19:24:05

Where can I read phantomjs manuals and find examples of website bots?

There was a need to get rid of various extensions for automating work with sites and hang everything on vps 24/7 using node + phantomjs. There is a module that builds a bridge between the node and the phantom. I want to find more information about writing bots, not tests. Is there anywhere to read? Or maybe someone has examples of really working bots that are of no value? Authorization, work with imported cookies, recognition protection

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Sundukov, 2015-12-15
@alekciy

If there is an idea about the webdriver protocol, then these questions would not arise. I mean, you just need to read the specification. And then a bot specialized for a specific site is written. For example, a piece from a bot, the authentication process:

/**
 *
 */
public function login()
{
  // Возможно мы уже залогинены
  if ( $this->isLogin() ) {

    return true;
  }

  $current_url = $this->_account->driver->getCurrentURL();

  $this->_account->driver->get($this->login_page);
  $html = $this->_account->driver->getPageSource();
  if ( $this->isLogin($html) ) {

    return true;
  }

  // Пытаемся найти требуемые для работы элементы
  try {
    $username    = $this->_account->driver->findElement(\WebDriverBy::xpath('//input[@id="username"]'));
    $password    = $this->_account->driver->findElement(\WebDriverBy::xpath('//input[@id="password"]'));
    $remember_me = $this->_account->driver->findElement(\WebDriverBy::xpath('//input[@name="autologin"]'));
    $submit      = $this->_account->driver->findElement(\WebDriverBy::xpath('//input[@name="login"]'));
  } catch (\Exception $e) {

    return false;
  }

  // Галочка автовхода
  $remember_me->click();

  // Задаем логин
  $username->click();
  $username->sendKeys($this->_account->login);

  // Задаем пароль
  $password->click();
  $password->sendKeys($this->_account->password);

  $submit->click();

  $html = $this->_account->driver->getPageSource();

  // Возможно нас забанили
  if ( preg_match('~закрыт доступ к конференции~iu', $html) )
  {
    throw new AccountBannedException('Account #' . $this->_account->id . ' is banned');
  }

  // Возращаемся на исходную страницу
  if ( !empty($current_url) ) {
    $this->_account->driver->get($current_url);
  }

  return $this->isLogin($html);
}

The problems of cookies, parallel sessions, recognition are already solved within the framework of a different infrastructure, i.e. at the application level.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question