Skip to content

Instantly share code, notes, and snippets.

@taojunxin
Last active April 23, 2020 15:39
Show Gist options
  • Save taojunxin/64b1b30def733df6ca3c749e3cd1a403 to your computer and use it in GitHub Desktop.
Save taojunxin/64b1b30def733df6ca3c749e3cd1a403 to your computer and use it in GitHub Desktop.
[获得URL里的文件名] #python #pathlib
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