-2

lets see,i have a link image from result of scraping.

e.g: https://xxxx-zzz/zzz/xxx/.png1234w

how i can removed string after .png meant "1234w"

Im tried using rsript() but didn't work string.rstrip(".png")

I dont know what my wrong,im just begging from python

alnyz
  • 91
  • 1
  • 1
  • 9

2 Answers2

0

Assuming you only want to remove the strings after the last '.png', you can do this:

s = 'https://xxxx-zzz/zzz/xxx/.png1234w'
print(''.join([s.rsplit('.png', 1)[0], '.png'])
>>>
'https://xxxx-zzz/zzz/xxx/.png'
Longwen Ou
  • 859
  • 4
  • 4
0

Can this meet your requirement?

>>> url='https://xxxx-zzz/zzz/xxx/.png1234w'
>>> import re
>>> re.findall('^(.*\.png).*$', url)
['https://xxxx-zzz/zzz/xxx/.png']
Quinn
  • 4,394
  • 2
  • 21
  • 19