How to read a file downloaded by selenium webdriver in python

后端 未结 3 1396
遇见更好的自我
遇见更好的自我 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:50

    You can get the last downloaded file from that location and then read the file:

    path = /path to folder
    list = os.listdir(path)
    time_sorted_list = sorted(list, key=os.path.getmtime)
    file_name = time_sorted_list[len(time_sorted_list)-1]
    

    and then u can read from this file. Hoping not multiple files are getting there by parallel processes.

    EDIT: Just saw comment that multiple instances are up for downloading, so other way around you can use urllib and download the file by using its url as:

    import urllib
    urllib.urlretrieve( "http://www.example.com/yourfile.ext", "your-file-name.ext") // you can provide unique-id to your file name
    

提交回复
热议问题