M
M
Maxim Valerievich2015-05-23 17:33:58
JavaScript
Maxim Valerievich, 2015-05-23 17:33:58

Is it possible to parse a page in the background with Rails + Ajax?

Hello. Interested in this question. I'm trying to make an ajax request that will parse the page.
There is a controller for example index and parser. Parser has a create method, for example, with the following code:

require 'open-uri'
  require 'nokogiri'
    user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.854.0 Safari/535.2"
    page = Nokogiri::HTML(open('http://ya,ru', 'User-Agent' => user_agent), nil, "UTF-8")


From the index controller, I send through the form with the url parameter ajax request to parser#create
. Only this comes in response:
RuntimeError in ParsersController#create

redirection forbidden: https://google.com/ -> http://google.com
    <div class="source hidden" id="frame-source-0">
      <div class="info">
        Extracted source (around line <strong>#224</strong>):
      </div>
      <div class="data">
        <table cellpadding="0" cellspacing="0" class="lines">
          <tr>
            <td>
              <pre class="line_numbers">


The redirection forbidden line is interesting, who is trying to redirect from https to http

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Valerievich, 2015-05-23
@S-anches

I'll answer myself, yes. The jamb was that the wrong line with the address reached.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question