Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
最後の小数点の後にすべてを切り取り、最後に「html」を追加しようとしています
html
<a href="http://www.youversion.com/bible/gen.1.ceb">http://www.youversion.com/bible/gen.1.ceb</a>
現在のコードは「gen.1.ceb」を返します
name = urlparse.urlparse(url).path.split('/')[-1]
名前が「gen.1.html」になるようにしたい
import re re.sub(r'\.[A-Za-z]+$','.html',url)
あなたはそのようにすることができます:
filename = urlparse.urlparse(url).path.split('/')[-1] # get file name name = filename.rsplit('.', 1)[0] + '.html' # change the extension