Python 3 remove the space after the last /

using python 3 when i run this code to get the urls i get a space in the url

how do i remove the space after the last /

thanks

# Import libraries
import requests
from bs4 import BeautifulSoup

# Connect to the URL
page = requests.get('https://www.meihoski.co.jp/movie/')
soup = BeautifulSoup(page.content, 'html.parser')
#get all links with href and add the missing part of the url to the front
for a in soup.find_all('a', href=True):
       print('https://www.meihoski.co.jp/movie/',a['href'])

i get a list of urls like this with a space need to remove the space after the /

https://www.meihoski.co.jp/movie/ meiho_tvcm_ma.mp4

Try:

print('https://www.meihoski.co.jp/movie/' + a['href'])
1 Like

thanks wisecracker works great

Since you're using python3, you can also take advantage of string formatting:

'https://www.meihoski.co.jp/movie/{}'.format(a['href'])

Check this out: 6.1. string � Common string operations � Python 3.4.10 documentation

1 Like