python find查找制定字符

2018-10-31  本文已影响0人  戒灵
url='https://www.amazon.com/Amazon-Fire-TV-Stick-With-Alexa-Voice-Remote-Streaming-Media-Player/dp/B00ZV9RDKK/ref=zg_bs_electronics_1?_encoding=UTF8&psc=1&refRID=3RE1Q3RPWH4FJZP7VVAN'
index = url.find('/dp/')
print(index)
asin = url[url.find('/dp/'):]#查找/dp/之后
url1='https://www.amazon.com'+asin
asin1=url1[:url1.find('/ref')]#查找/ref之前
print(asin1)

运行结果为:https://www.amazon.com/dp/B00ZV9RDKK

上一篇下一篇

猜你喜欢

热点阅读