medBouzid
medBouzid

Reputation: 8382

Is it possible to get the html produced by a script

I have a URL from a third party site which should be the source of a script tag, something like this:

<script src="<%= @url %>"></script>

The above code shows a webform.

I would like to get the html code resulted by that code and store into a variable, something like this :

html_code = get_html('<script src="<%= @url %>"></script>')

Is that possible using Ruby/Rails (maybe using nokogiri) ?

Upvotes: 0

Views: 67

Answers (2)

tadman
tadman

Reputation: 211560

If you're using jQuery in the browser and that code shows up in a well defined location, for example a <div> with a specific id then you can just grab it using your browser's JavaScript console:

$('#the_id').html()

That will show the raw HTML of that element presuming it dumps its content in an element with the ID the_id. You can use whatever CSS selector works.

Where that HTML goes in your document is impossible to tell from your example. A <script> can add any elements it wants anywhere in your document. You'll have to look around to see where it goes.

Upvotes: 1

jfriend00
jfriend00

Reputation: 707238

Load the page into a browser and then do View/Source in the browser. This will let you view the generated web page and you can find what URL was put into the <script> tag.

Upvotes: 0

Related Questions