【概要】Youtubeの概要欄に掲載されているメールアドレスを抽出し、リスト化するプログラムを開発していただきたいです。
【目的】動画編集フリーランスの営業活動に使用したいと思っています。
【依頼背景】営業活動を行うにあたり、顧客獲得のためのリスト抽出が必要となりました。
【提案の際のお願い】提案される際は「同時に抽出できる項目」についてご提示頂けますと検討がしやすいです。宜しくお願いいたします。
参考までに、友人が書いてくれたコードを添付させていただきます。
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
DEVELOPER_KEY = "YOUR_DEVELOPER_KEY"
YOUTUBE_API_SERVICE_NAME = "youtube"
YOUTUBE_API_VERSION = "v3"
def get_channel_email(channel_id):
youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION,
developerKey=DEVELOPER_KEY)
try:
channels_response = youtube.channels().list(
part="snippet",
id=channel_id
).execute()
for channel in channels_response["items"]:
if "email" in channel["snippet"]:
return channel["snippet"]["email"]
else:
about_response = youtube.channels().list(
part="snippet",
id=channel_id,
fields="items(snippet(description))"
).execute()
description = about_response["items"][0]["snippet"]["description"]
email = extract_email(description)
return email
except HttpError as error:
print("An error occurred: %s" % error)
return None
def extract_email(text):
import re
email_regex = r'[\w\.-]+@[\w\.-]+\.\w+'
matches = re.findall(email_regex, text)
if matches:
return matches[0]
else:
return None
# チャンネルIDを入力してメールアドレスを取得する
channel_id = "CHANNEL_ID"
email = get_channel_email(channel_id)
if email:
print("Email found: ", email)
else:
print("No email found.")