How to read a file downloaded by selenium webdriver in python

后端 未结 3 1423
遇见更好的自我
遇见更好的自我 2021-01-07 08:13

I am using selenium with webdriver in python to download a csv file from a site . The file gets downloaded into the download directory specified. Here is an overview of my c

3条回答
  •  情歌与酒
    2021-01-07 08:58

    Downloading files in Selenium is never a good idea. You cannot control where and under which filename the file is downloaded, and if you want to find out, then you have to use dirty hacks. It depends on the browser and its settings and if the same file has already been downloaded before or not.

    Plus, you have to take care of deleting the file after the download, bc otherwise, numerous copies of the same file will spam your hard drive until it's completely full.

    If possible, you should call something like

    string downloadUrl = ButtonDownloadPdf.GetAttribute("href");
    

    and then handle the downloading yourself, using conventional methods, not Selenium.

提交回复
热议问题