File size: 1,238 Bytes
3141bb9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import requests
from bs4 import BeautifulSoup
import gradio as gr
def search_google_videos(query):
# 検索クエリをエンコードしてGoogleのURLを作成
url = f'https://www.google.com/search?q={query}&tbm=vid'
# GoogleにGETリクエストを送信
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
}
response = requests.get(url, headers=headers)
# レスポンスを解析
soup = BeautifulSoup(response.text, 'html.parser')
# 動画の検索結果を取得
results = []
for result in soup.find_all('div', class_='BVG0Nb'):
title = result.find('h3').text
link = result.find('a')['href']
results.append(f"Title: {title}\nLink: {link}")
return "\n\n".join(results)
# Gradio インターフェースを作成
iface = gr.Interface(
fn=search_google_videos, # 実行する関数
inputs="text", # テキスト入力を使用
outputs="text", # テキスト出力を使用
title="Google Video Search", # タイトル
description="Enter a query to search videos on Google." # 説明
)
# Gradio アプリを起動
iface.launch()
|