Last active
April 23, 2020 15:39
-
-
Save taojunxin/64b1b30def733df6ca3c749e3cd1a403 to your computer and use it in GitHub Desktop.
[获得URL里的文件名] #python #pathlib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urllib.parse import urlparse | |
from pathlib import Path | |
url = "http://example.com/some/long/path/a_filename.jpg?some_query_params=true&some_more=true#and-an-anchor" | |
a = urlparse(url) | |
a.path # '/some/long/path/a_filename.jpg' | |
Path(a.path).name # 'a_filename.jpg' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment