Download Python Selinium File

Asked 2 years ago, Updated 2 years ago, 38 views

I'm currently trying to download a file to Python Cellinium. Using import os, I even succeeded in renaming the file

Rename does not work if the file name has the same symbol as the special character. It seems that replace does not work for os.rename.

python selenium

2022-09-21 15:46

4 Answers

First of all, there is no problem with os.rename.

The problem is that the glob module is misused.

[] glob when processing special characters such asEscape (patchname) must be used.

However, the glob module is usually used to obtain a set of file names from that path using regular expressions. That is, *.txt to get all the txt files in that directory.

If you know a clear file path, as is the case with the questioner, glob is an unnecessary method.

https://docs.python.org/ko/3/library/glob.html

Please refer to the link above for specific instructions.


2022-09-21 15:46

(_ 64, 86 x) 29 : fedora os, 3.7.2 Draws up : python.

There was no problem in the following cases.

os.rename("/home/allinux/aaaa[.txt", '/home/allinux/bbbb.txt')

Please test the name only and post a problem if there is a problem.


2022-09-21 15:46

path = root_dir + "/" + '[Notice] 2019.hwp'
print(path)
for f, filename in enumerate(glob.glob(path)):
    os.rename(filename, os.path.join(root_dir, 'aaaaa'))

It is not being processed if:


2022-09-21 15:46

I solved the issue of special characters that I asked you. It was resolved by adding str to the file name without using the glove function.

However,

The file name is 2019 (Amendment 1)_1.hwp It is not renamed in the following cases.

path = str(dir + "/" + str(name))   
os.rename(dir+"/"+str(name),dir+"/"+str(d))

name: 2019 (Amendment 1) 1.hwp id: aaa_01 2019 Amendment 1_1.hwp

You want to change from name value to id value. I'm going to give you a space and a space. Is there a way?


2022-09-21 15:46

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.