2007年09月04日 星期二 12:15
import urlparse url='http://www.xxx.com/xxx/a.aspx' protocol,host,path,param,query,fragment=urlparse.urlparse(url) path=path.rsplit("/",1)[0] new_url=urlparse.urlunparse((protocol,host,path,param,query,"")) print new_url 这个通用性比较强,我写爬虫时就是这么处理的。
2007年09月05日 星期三 11:02
doudou的是正解……楼主提到的需求,其实把问题想得太简单了……例如: http://www.test.com/test/test.php?path=bbb/ccc/ddd/eee 这样的路径……前面各位所用的方法就都要取错了…… 楼主可以看一下urlparse模块里的url拆分算法……如果对性能有要求……可以自己进一步优化…… -------------- next part -------------- An HTML attachment was scrubbed... URL: http://python.cn/pipermail/python-chinese/attachments/20070905/440e4cb2/attachment.htm
Zeuux © 2025
京ICP备05028076号