Read dynamic PDF from Ruby Watir
I figured out a solution.
In the profile for firefox you can set the plugin.scan.Acrobat to "999" which will effectively disable the PDF plugin.
profile = Selenium::WebDriver::Firefox::Profile.new
profile['plugin.scan.Acrobat'] = "999"
b = Watir::Browser.new :firefox, :profile => profile
Opening PDF's using `target=blank` fails on Android Chrome
Make the URL relative to the site domain
<a href="/sample.pdf" target="_blank">Open PDF</a>
<!-- Not <a href="/example.com/sample.pdf>Open PDF</a> -->
This allowed the links to download without issue on the Google Chrome app (specifically on Samsung).
downloading a file that comes as an attachment in a POST request response in PhantomJs
I've found a way to do this using casperjs (it should work with phantomjs alone if you implement the download function using XMLHttpRequest, but i've not tried).
I'll leave you the working example, that tries to download the mos recent PDF from this page. When you click the download link, some javascript code is triggered that generates some hidden input fields that are then POSTed.
What we do is replace the form's onsubmit function so that it cancels the submission, and get the form destination (action) and all its fields. We use this information later to do the actual download.
var casper=require('casper').create();
casper.start("https://sede.gobcan.es/tributos/jsf/publico/notificaciones/comparecencia/ultimosanuncios.jsp", function() {
var theFormRequest = this.page.evaluate(function() {
var request = {};
var formDom = document.forms["resultadoUltimasNotif"];
formDom.onsubmit = function() {
//iterate the form fields
var data = {};
for(var i = 0; i < formDom.elements.length; i++) {
data[formDom.elements[i].name] = formDom.elements[i].value;
}
request.action = formDom.action;
request.data = data;
return false; //Stop form submission
}
//Trigger the click on the link.
var link = $("table.listado tbody tr:first a");
link.click();
return request; //Return the form data to casper
});
//Start the download
casper.download(theFormRequest.action, "downloaded_file.pdf", "POST", theFormRequest.data);
});
casper.run();
Note: you have to run it with --ignore-ssl-errors, as the CA they use isn't in your browser default CA list.
casperjs --ignore-ssl-errors=true downloadscript.js
Related Topics
How to Condense Summable Metrics to a Unique Identifier in a Ruby Table
How to Return the Number of Devise Users Currently Logged In
Ruby Check Whether Program Is Currently Being Closed
Rails "Template Is Missing" Error
How to Print a Line Number in Ruby
Ruby - Permutation Between Elements of an Array
How to Share Image and Description Using Social_Share_Button in Rails
How to Run Selenium Script on Ie
Error Pushing Ruby on Rails to Heroku
Use Variable in Parameter Ruby on Rails
Instagram Ruby Gem - Unable to Reach Callback Url
Create a Titleize Method, That Excludes "Little Words"
How to Display a Link to Individual Microposts? (Ruby on Rails 3)
Deleting Blank Lines After Loop
How to Marshal a Hash with Arrays
Metasploit Induction of Bundle and Rake