Как я могу войти на сайт с кодировкой Angular .io, используя Nokogiri и Capybara / poltergeist? - PullRequest
0 голосов
/ 21 марта 2020

Я пытаюсь войти на сайт с целью очистки, и похоже, что они используют Angular .io. Сначала я безуспешно пытался использовать Mechanize и logger, поэтому теперь я использую Capybara и Nokogiri.

Веб-страница входа на сайт HTML код:

<div _ngcontent-yhs-c14="" class="container">
  <div _ngcontent-yhs-c14="" class="row justify-content-center align-items-center">
   <div _ngcontent-yhs-c14="" class="col-md-6 col-sm-11">
    <div _ngcontent-yhs-c14="" class="login-component">
     <h3 _ngcontent-yhs-c14=""><strong _ngcontent-yhs-c14="">Iniciar sesión</strong></h3><!---->
     <form _ngcontent-yhs-c14="" autocomplete="on" id="loginForm" novalidate="" class="ng-pristine ng-invalid ng-touched">
      <div _ngcontent-yhs-c14="" class="form-group">
        <label _ngcontent-yhs-c14="" for="username">Correo electrónico:</label>
        <input _ngcontent-yhs-c14="" class="form-control ng-pristine ng-invalid is-invalid ng-touched" email="" name="user" ngmodel="" required="" type="email">
        <!---->
       <div _ngcontent-yhs-c14="" class="invalid-feedback ng-star-inserted">
          <!---->
          <div _ngcontent-yhs-c14="" class="ng-star-inserted"> El campo requerido. </div>
       </div>
      </div>
      <div _ngcontent-yhs-c14="" class="form-group">
        <label _ngcontent-yhs-c14="" for="pwd">Contraseña:</label>
        <input _ngcontent-yhs-c14="" autocomplete="off" class="form-control ng-untouched ng-pristine ng-invalid" name="pwd" ngmodel="" required="" type="password">
        <!---->
       </div>
      <div _ngcontent-yhs-c14="" class="contenedor_iniciar form-group d-flex ">
        <div _ngcontent-yhs-c14="" class="form-group login-footer">
         <p _ngcontent-yhs-c14="" class="info_accesos">Los datos de acceso son sensibles a mayúsculas y minúsculas.</p>
         <a _ngcontent-yhs-c14="" class="text-center-small btn btn-link p-0 "> ¿Olvidaste tu contraseña? <span _ngcontent-yhs-c14="" class="br"></span> Haga clic aquí para recuperar su acceso. 
         </a>
        </div>
        <input _ngcontent-yhs-c14="" class="btn btn-iniciar" type="submit" value="Ingresar" disabled="">
       </div>
     </form>
     <swal _ngcontent-yhs-c14="" input="email" inputplaceholder="Correo Electronico" title="Recupera tu contraseña" type="info"></swal>
    </div>
   </div>
  </div>
</div>

Я прошел через "* 1006 Учебник * Scraping data with Capybara", чтобы попытаться войти в систему, прежде чем пытаться выполнить синтаксический анализ и начать с этого:

require 'nokogiri'
require 'net/http'
require 'capybara/poltergeist'

# get the HTML from the website
uri  = URI("http://letech.mx/login")
body = Net::HTTP.get(uri)

# pry at the bottom so we can play with it
require "pry"
require 'capybara/poltergeist'
binding.pry 

# The object we'll interact with
browser = Capybara.current_session

# Go to a web page (first request will take a bit)
url = "http://letech.mx/login"
browser.visit url

# Save the page locally, and open it (this is what Launchy does) 
browser.save_and_open_page
ls -v browser
browser.current_url

#fill the form with user and password and click on login button.
browser.fill_in 'user', with: 'user@email.com'
browser.fill_in 'pwd', with: 'password'
browser.click_on 'Ingresar'

Когда я выполняю последнюю команду click_on, я получаю ошибку:

TypeError: undefined is not an object (evaluating 'e.top')

Как мне пройти через окно входа в систему, чтобы я мог начать очистку?

...