[Tutor] Using Python to access .txt files stored behind a firewall as .exe files
Mats Wichmann
mats at wichmann.us
Mon May 1 20:47:25 EDT 2017
On 05/01/2017 06:12 PM, Ian Monat wrote:
> Thank you for the reply Mats.
>
> I agree the fact that files are wrapped in an .exe is ridiculous. We're
> talking about a $15B company that is doing this by the way, not a ma and pa
> shop. Anyways...
>
> If I understand you correctly, you're saying I can:
>
> 1) Use Python to download the file from the web (but not by using a
> webscraper, according to Alan)
> 2) Simply ignore the .exe wrapper and use, maybe Windows Task Manager, to
> unzip the file and place the .txt file in the desired folder
>
> Am I understanding you correctly?
>
> Thank you -Ian
Once you figure out the filename to download - and this may require some
scraping of the page - I'm thinking something like:
import subprocess
downloaded_filename = "something.exe" # whatever you found to download
cmd = "7z x " + downloaded_filename
res = subprocess.check_output(cmd)
examine res to make sure there was something to extract
then go on and fish file(s) out of the zipfile
I have nothing to experiment with this on, so it's just "thinking out loud".
I have at some point used 7z (and most of the other windows archivers
that you'd consider "third party" can probably do something like)
interactively to fish a zip out of an exe, but there's no reason it
wouldn't work from the command line that I know of.
More information about the Tutor
mailing list