How to use a download link to download a file in Python - html

Basically I am trying to write a script which will grab certain files on a webpage and download it to specific folders.
I am able to complete this with most of the webpages using Python, Selenium, and FirefoxPreferences.
However, when I try to grab off of this specific webpage, due to credential rights, I can't parse the html.
Here is the question. I am able to grab the download link for the file, and I can open a browser and have the open/save widget pop up. I can't however click or actually down the file any further. I have already set the Firefox Preferences to not show this widget, to download automatically, and to a specific file. This is ignored for some reason, and I am still left staring at the open browser, with the save/open widget.
How do I use the download link of a file to download to specific folder using Python... Selenium... any other related CS tricks. I don't want to build a bot to click the save for me. Too "hacky" and this is a company project.
Thanks!

you can try urllib
urllib.urlretrieve(<url>,<filename_with_path>)

import urllib
testfile = urllib.URLopener()
testfile.retrieve("http://randomsite.com/file.gz", "file.gz")
The good way to download a file with python.
Refer Here

Related

Can you save an image in angular without the backend?

I want to save an image in angular's Assert folder or in a folder created by me. I occupy the input file and a button, nothing more when I save the selected image, I want it to be uploaded or copied to said folders or folder. Can this be done without the backend?
I have been looking for information and watching videos but most of them either use firebase or some other service, I just want it locally. Please, your help would help me a lot.
If I understand your question correctly, you are asking if, at runtime, you can create a file in your Angular applications' 'assets' folder.
This is not possible, because the 'assets' folder is a compile-time artifact. It only exists in your source code tree. In the compiled application, the assets folder does not exist.
Furthermore, when the folder exists, it only does so on the computer on which you wrote the application. The user is running it in their web browser, which is generally running on their computer, not yours.
Now, if you are just asking if you can save a file on the user's computer, take a look at File Save functionality in Angular

Persistent Edit In Chrome DevTools

There's an online tool that I'd like to tweak. It depends upon a JSON file. The easiest way for me to make the changes that I desire is to edit this JSON file directly, which I'm doing using the "Edit text" feature of Chrome DevTools. Next, I need to reload the main webpage so that it fetches the edited JSON file. Of course, this doesn't work because the webpage fetches the resource from the server. Is there any way to make the webpage temporarily load my edited JSON file?

Convert .json to ipynb

I am taking a course that uses ipython notebook. When I try to download the notebook (through File -> Download as -> ipython notebook), I get a file that ends with ".ipynb.json". It doesn't open as an ipython notebook but as a .json file so something like this:
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---\n",
"\n",
"_You are currently looking at **version 1.1** of this notebook. To download notebooks and datafiles, as well as get help on Jupyter notebooks in the Coursera platform, visit the [Jupyter Notebook FAQ](https://www.coursera.org/learn/python-data-analysis/resources/0dhYG) course resource._\n",
"\n",
"---"
]
},
...
}
I've tried deleting the ".json" in the file name and it doesn't work. How can I convert this file back to something that can be opened and run as an ipython notebook? Thank you very much!
My Solution: just remove the filename extension .json. for example, change myfile.ipynb.json to myfile.ipynb. Then, you can open it by a click in jupyter notebook !
I have encounter the same problem as you did. I found a link that describe what ipynb exactly is. see here http://ipython.org/ipython-doc/rel-1.0.0/interactive/nbconvert.html. It says ipynb file is actually json file. Hope this
On the Mac you could go and
Right click on the filename.ipynb.json
Click on Get Info from the list.
From the Get Info window, find the section Name&Extension remove the extension/suffix .json from the file name.
Hope that helps!
Are you trying download this from Github? Especially on Google Chrome browsers, I've had issues download .ipynb files using right click > Save link as... I'm not sure if other browsers have this issue (Microsoft Edge, Mozilla Firefox, Safari, etc.).
This causes issues since when downloading, it doesn't completely download the file usually and it becomes corrupted so you can't download an IPython notebook that may run properly. One trick when trying to download .ipynb files on Github is to click it, click Raw, then copy everything (Ctrl + A) and paste it into a blank file (using text editors such as Notepad, Notepad++, Vim, etc.) and save it as "whatever_file_name_you_choose.ipynb". Then you should be able to properly run this file, assuming a non-corrupted file was uploaded to Github.
A lot of people with very large, complicated IPython notebooks on Github will inevitably run into this issue when simply trying to download with Save link as.... Hopefully this helps!
I opened it as/with nbviewer and then selected it all and saved it as a "txt" file that I then opened in Notepad++. I then resaved it as a file with the extension ipynb and opened it in my jupyter notebook ok.
The easy thing to do is to copy the JSON contents into a notepad and save it again with .ipynb extension
Just remove the .json file extension leaving the .ipynb one, as pointed out by the following related post: https://superuser.com/questions/1497243/why-cant-i-save-a-jupyter-notebook-as-a-ipynb. As #jackie already said, you should consider them as .json files meant only to be edited by the IPython Notebook app itself, not for hand-editing.
Use a simple trick. Let that file get downloaded automatically. Re-download it again then it will prompt you to download and replace that file. At that time, you save that by replacing .json to .ipynb
After downloading the file with ipynb.json, Take the following steps:
Go your terminal/command line window
Navigate to the directory where your file is
Type:
windows OS: rename yourfile.ipynb.json to yourfile.ipynb
Unix/Linux: mv yourfile.ipynb.json to yourfile.ipynb
This work perfectly for me.
i tried this method and it worked. Just copy, paste it in notepad and save as "file_name.ipynb". hope this works for you too.

How to run html with json files in SharePoint?

I am making SharePoint spaces for various departments in insurance company. One of them wants to save and share their outputs via SharePoint. That outputs are maps with risk areas. Because maps includes many data layers, all the files are in one folder.
I have uploaded a folder with CSS, JSON, JS and HTML files to the library in SharePoint, but when I doubleclicked on HTML file, the page will not load. I think it's due to the JSON files.
What I need is to run whole page correctly with simple doubleclick.
Can anyone give me advice how to run other files supporting HTML with doubleclicking on HTML file?
Thank you.
I've had this same issue. To get the HTML to play in the browser (without SharePoint trying to make you download it), you need to rename the HTML file to an ASPX file.
To do this, you need to be in the Windows Explorer view (from a document library, go Library > Open with Explorer). Then change the file name from index.html to index.aspx.
However, if you're also using JSON files, that could be an issue. SharePoint prohibits you from uploading JSON files unfortunately.

Can I use asp FileUpload to select a folder?

I need something like the FileUpload control in asp.net that will allow the user to browse for a folder and enter a file name of a new file to upload.
From what I've seen FileUpload requires a file to be selected. It seems that html input type="file" has the same requirement.
Thanks!
Selecting an entire folder is not possible in FileUploadControl as it is meant for a single file. Although you can have a Multi File Selection. Multiple File Upload User Control
C# has build-in FTPrequest class where you can create folders, upload files, delete files etc.
If you want to upload folders from a webpage, you cannot use this technology in the browser, then you will have to use a rich-client such as Java, Flash or similar plugin.
If you can provide the users with a Windows or Mac client, you can use C# (either .NET or Mono) for the FTP transfer.
ZIP files arent a problem for ASP.net nor C#, but you still only upload 1 file (zip-archive) and then its up to the server to unzip it using eg. C#. Look at 7-Zip which is opensource, then you might get some ideas too.
You could also just try and use the build-in lib for it (compression):
http://www.eggheadcafe.com/community/csharp/2/10050636/how-to-compress-and-decompress-file-in-c.aspx
or try this link...
http://www.aurigma.com/docs/iu7/uploading-folders-in-aspnet.htm