Python Forum
Issues running Selenium to download zip file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issues running Selenium to download zip file
#1
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).
Reply
#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.
Recommended Tutorials:
Reply
#3
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
Reply
#4
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!
Reply
#5
either
from selenium import webdriver
or use
selenium.webdriver
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Login and download an exported csv file within a ribbon/button in a website Alekhya 0 2,652 Feb-26-2021, 04:15 PM
Last Post: Alekhya
  Webcrawler with Selenium and Browsermob, Har file not complete Smartkoncept 0 1,308 Jul-23-2020, 08:06 AM
Last Post: Smartkoncept
  Cannot download latest version of a file TheTechRobo 3 2,278 May-20-2020, 08:33 PM
Last Post: TheTechRobo
  error when running headless selenium julio2000 2 4,552 Feb-01-2020, 12:41 PM
Last Post: julio2000
  download pdf file from website m_annur2001 1 2,984 Jun-21-2019, 05:03 AM
Last Post: j.crater
  Selenium Web Driver Exe not running in other PC's Utkarsh29 2 4,468 Feb-28-2019, 05:48 PM
Last Post: snippsat
  Flask generating a file for download darktitan 0 3,346 Dec-30-2018, 02:02 PM
Last Post: darktitan
  selenium - chrome crashes when chrome is running. RvBVakama 4 15,283 Dec-16-2018, 06:32 PM
Last Post: metulburr
  Error when running .py file but not when entering exact same code in CLI Broadsworde 3 2,736 Dec-11-2018, 09:06 AM
Last Post: Broadsworde
  selenium not running firefox Sanlus 5 4,915 Aug-31-2018, 10:37 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020