I have url that has a following structure:
https://example.com/string?rest
I am trying to extract only the 'string' part and so far I can only think of using
response.url.split('/')[3]
to extract everything after third '/' Is it possible to extract the part after third '/' and before the '?' sign?
Might be able to use something in urllib.parse
:
from urllib.parse import urlparse
print(urlparse(response.url).path.split('/')[-1])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.