🔍
pythonでgoogle custom search apiを使おう
google検索をpythonでしよう!
今回使用するパッケージをインストールしよう
今回使用するパッケージはこれgoogle-custom-searchです。
pip install google-custom-search
APIキーなどを取得しよう
ちょっと書く気力がないのでこちらを参考にしてください。
ソースコード
from google_custom_search import custom_search
apikey = "あなたのapikey"
engine_id = "あなたのエンジンID"
custom_search = custom_search(apikey = apikey, engine_id = engine_id)
name = input("検索したいキーワードを入力してください")
result = custome_search.search(name)
print("検索結果:")
print(f"タイトル:{result.titles[0]}")
print(f"URL:{result.urls[0]}")
最後に
実はこの記事が使ったパッケージは自分で作りました。
改善点がありましたらコメント欄にお願いします。
Discussion