Download dynamically generated pdf from using selenium - python-3.x

So I'm trying to download pdf files from an ancient internal web system. I put in a request and based on my request parameters, it generates a new pdf and shows it in a new window. Since the pdfs are generated dynamically, there is no real url I could download.
I'm trying to figure out how I would download the file after it has generated and opened up in the new window.
The pertinent part of the page's source seems to be this:
<body onload="document.FormForDownload.submit();">
<form name="FormForDownload" method="get" action="./download.pdf" target="iframePDF">
<iframe name="iframePDF"></iframe>
</form>
</body>
I'm open to using the requests library or urllib or anything people suggest. ANy ideas? Working in python btw.
If I suppress chrome's own PDF viewer to get it to automatically download the pdf, I get a page that looks like this:
Clicking the open button will give me this page:
This is because the url generated is one time use only, to generate the url again, I have to request the pdf again.

Related

Nodejs can selenium be used to parse html text without opening a browser?

I'm trying to parse an html page I already have as text, and I've used selenium quite a bit before. I was wondering if it's possible to use selenium without it actually launching a browser. I don't need js to be run, I don't need to interact with the page, I just need to parse static html.

Importing knowledge base from MD File

How can we fetch the QnA Pair from the URL which runs JS and then renders the DOM? The file is in markdown format and renders into HTML via running JS.
I came to know that the QnA Maker only searches the HTML contents. I want to have QnA pairs from a markdown file. For example:
This works in QnA: https://github.com/gulpjs/gulp/blob/master/docs/FAQ.md
While this not: https://raw.githubusercontent.com/gulpjs/gulp/master/docs/FAQ.md
I am able to get the content as a second one from a page, but it's of no use as QnA doesn't support raw markdown. It supports in the form of HTML and the page I am requesting renders it after running JS.
I tried requesting with Postman too and body only contains Please enable JS and the same is happening with QnA.

odoo base64 image not working on website for custom module

I am creating a custom module. Where in the backend user will be able to upload background image of a section. I have a binary field in the backend for that.
But for some reason the image is not showing. Here is the line of qweb code I am using -
<div id="comments1" class="parallax-section" t-att-style="'background-image: url(data:image/png;base64,'+res_company.website_logo_img+');'">
This loads the data in binary format incompatible way.
Following is the screenshot when I first load the webpage and image not shows-
Google developer Tools inspect element view
Following is the screenshot when I just take than line in editable mode and hit enter. The image shows nice and clear:
Google developer Tools inspect element view
Can anyone tell me what is the problem?

How to set the title of a pdf file in browser?

I am using nodejs server to serve static files. When the pdf file is served, the browser displays the title as URL of the pdf path.
127.0.0.1:8080/docs/sample
How can I set this to a custom title say "Sample"
I have tried following things but no luck :
res.setHeader('Content-Disposition', 'inline;filename="sample.pdf"');
Setting meta tag of pdf file as "sample"
Any help will be much appreciated.
If you're using a static file server, then yes you are serving it as a download. Modern browsers often contain a built-in PDF viewing plugin, so instead of asking the user where to save the file, the browser will instead just display the PDF right in a browser tab. It still downloaded it, it just saved it to some temporary cache on your machine in that case.
What I'm getting at is that you cannot control the browser title in that case because it's just the browser trying to be nice and make things convenient for the user. The PDF file itself would have no idea if it was being displayed in the browser's built-in viewer or in Adobe Reader on the desktop. There are no HTTP headers you could send down to set the title either because browsers expect page titles to be set from HTML or JavaScript running on an actual web page.
Now, if you were to embed the PDF file in an HTML page with some kind of PDF viewer then you could control the page title with a simple <title>some title</title> tag or calling document.title = 'some title'; from JavaScript. That works because the browser is rendering an actual web page that you control, and that page just happens to have an embedded PDF viewer on it.
Here's an example of an embeddable PDF viewer. http://pdfobject.com/
//hack alert
You could trick the browser by setting the last fragment of the url to whatever you like . i.e. change sample in your example to the desired title.
(tested in chrome 58.0.3029.110)
HTH

chrome.browserAction.setPopup() - local html files only?

I would like to modify my extension's popup dynamically (at run-time). And want to specify a custom popup HTML file that's loaded from my server.
In Firefox, I can easily accomplish this with XUL overlays which I can specify at run-time.
And document.loadOverlay() does allow me to specify a 'remote' URL for the overlay.
Is the same possible in Chrome?
I've been playing with chrome.browserAction.setPopup( details ) API, but it seems that the details.popup param must specify a local file, and not a remote URL.
I have answered this exact same question on the Chromium-Extensions mailinglist.
There is no API to load external popups but you can do that with plain JavaScript. What you could do (I have done that in the past):
Use an iframe + extension messaging within the popup. The iframe
points to some external url not hosted in the extension.
Use templates (jQuery templates example), load those template files to
your background page, and just use them to construct your popup.
Download the html contents using XHR and load them within the popup
by constructing the DOM.
I usually use the template approach, but I use the popup iframe approach when I want to manage the entire popup in the server side so I don't have to push updates to the extension gallery. I am not a fan of downloading the HTML contents, templating seems safer.
Hope this helped!

Resources