I got a list of URLs from a csv file in Python and stumbled when I wanted to combine the URLs, so make a note
import os.path
channel_urls = ['/channel/UCVrJcoR8hUN9Rn7uPI4z6NQ']
for i in channel_urls:
root_url = 'https://www.youtube.com'
channel_url = ('%s' % i)
channel_about_url = urlparse.urljoin(youtube_url, channel_url, 'about')
print(self.open_channel_url)
# /channel/UCVrJcoR8hUN9Rn7uPI4z6NQ/about // 「https://www.youtube.com "does not enter
First install the module
(The following commands are picked up from the output of $ histroy
, so not all are needed)
tamenal.
$ pip3 install urllib3
$ pip install git+https://github.com/mitsuhiko/flask-oauth
$ pip install urlparse3
Source
sample.py
try:
import urlparse
except ImportError:
import urllib.parse as urlparse
channel_urls = ['/channel/UCVrJcoR8hUN9Rn7uPI4z6NQ']
for i in channel_urls:
root_url = 'https://www.youtube.com'
channel_url = ('%s' % i)
channel_about_url = urlparse.urljoin(youtube_url, channel_url, 'about')
print(self.open_channel_url)
# https://www.youtube.com/channel/UCVrJcoR8hUN9Rn7uPI4z6NQ/about
reference https://qiita.com/Go-zen-chu/items/d7e6b9af0bd90c7aabca https://www.it-swarm.dev/ja/python/python%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%ABurlparse%E3%82%92%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB%E3%81%A7%E3%81%8D%E3%81%BE%E3%81%9B%E3%82%93/961197002/ https://github.com/heroku/kafka-helper/issues/6