Python Forum

Full Version: Issues running Selenium to download zip file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all. Self-taught Python noob here. I'm trying to write a short python script to visit a web page and simulate the user clicking a download button to download a zip file. The url of this zip file changes frequently, hence the need to simulate clicking the button (the site's url remains the same). I'm using the package "selenium" to do this. Please let me know if there's anything better out there!

Whilst testing my first attempt, I've noticed the first line of my script (below) seems to be causing issues:

from selenium import webdriver

The script seems to produce the output below (even with all code stripped out leaving just the one line of code above).

https://gyazo.com/23b2f2d66e5169182b8764772aefd7bc

The script is currently being called by a cmd window as part of a larger process. If I manually type the command above into a Python window, it seems to work correctly.
If it helps, I'm using Python 2.7 (I have to as this is the version bundled with ArcGIS, the program I'm using for most other tasks in this group). I've got the latest version of Selenium (3.0.2).
Quote:I'm trying to write a short python script to visit a web page and simulate the user clicking a download button to download a zip file. 
Quote:The script is currently being called by a cmd window as part of a larger process. If I manually type the command above into a Python window, it seems to work correctly.
From my perspective it looks like you just successfully imported selenium's webdriver. What are the issues you are talking about? 

Read the help docs about what to put into each question
http://python-forum.io/misc.php?action=help&hid=20

Dont post screenshots of code or a terminal output, just copy and paste it using code tags here.
Thanks metulburr. Apologies for attaching screenshots incorrectly etc!

As far as I'm aware (correct me if I'm wrong!), simply importing webdriver shouldn't cause python to do anything visibly on screen and the script should move on to the next line of code. I've heavily simplified my script so it is now just a batch file opening a one-line python script that imports webdriver from selenium. Nothing else. I've pasted the code and the output below. What is causing this "Thread" behaviour? Once the  If I open an IDLE window and run the python script from there, it runs fine (i.e. just loads webdriver, doesn't display anything and allows me to run further commands).

Batch file:
"C:\Python27\python.exe" "C:\Users\david.hughes\Desktop\Download_NRW_FZ2_shp.py"

Simplified python script:
from selenium import webdriver
Output:
Quote:C:\Users\david.hughes\Desktop>"C:\Python27\python.exe" "C:\Users\david.hughes\De
sktop\Download_NRW_FZ2_shp.py"
Thread-1: Wed Jan 11 10:18:41 2017
Thread-2: Wed Jan 11 10:18:43 2017Thread-1: Wed Jan 11 10:18:43 2017

Thread-1: Wed Jan 11 10:18:45 2017
Thread-2: Wed Jan 11 10:18:47 2017Thread-1: Wed Jan 11 10:18:47 2017

Thread-1: Wed Jan 11 10:18:49 2017
Thread-2: Wed Jan 11 10:18:51 2017
Thread-2: Wed Jan 11 10:18:55 2017
Thread-2: Wed Jan 11 10:18:59 2017
I've also since noticed that using the code:

import selenium
fp = webdriver.FirefoxProfile()
produces the error:

Quote:NameError: name 'webdriver' is not defined

But running help(selenium) suggests there is a package called webdriver that has been successfully loaded. This behaviour only occurs when I run the python script from a batch file. Running it in IDLE, works fine.

Cheers!
either
from selenium import webdriver
or use
selenium.webdriver