如何使用python从网址的背面删除“ 1”?

时间:2018-12-03 10:57:08

标签: python-3.x

https://www.amazon.com/I3565-A453BLK-PUS-Dell-Laptop-Dual-Core-Processor/product-reviews/B07BLPHRX9/ref=cm_cr_arp_d_viewopt_srt?ie=UTF8&reviewerType=all_reviews&filterByStar=positive&pageNumber=1&sortBy=recent

我需要删除URL中的最后一个“ 1”,以便可以在我的代码中实现它。 python中是否有任何方法可以删除“ 1”?

1 个答案:

答案 0 :(得分:2)

a= "https://www.amazon.com/I3565-A453BLK-PUS-Dell-Laptop-Dual-Core-Processor/product-reviews/B07BLPHRX9/ref=cm_cr_arp_d_viewopt_srt?ie=UTF8&reviewerType=all_reviews&filterByStar=positive&pageNumber=1&sortBy=recent"

b= a.replace("pageNumber=1","pageNumber=")

print(b)

这是您的操作方式。使用string.replace()替换字符串中的任何内容。

Check here for replace method and its use