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”
你可以这样做:
filename = urlparse.urlparse(url).path.split('/')[-1] # get file name name = filename.rsplit('.', 1)[0] + '.html' # change the extension
import re re.sub(r'\.[A-Za-z]+$','.html',url)