スクレイピングしてタイトルを取得する
検索結果を表示するときにそのページのタイトルが必要となる。
ここではWikipediaのグーグル紹介ページ(Google - Wikipedia)のタイトルをスクレイピングして取得した。言語はPython3,ライブラリはbeautifulsoupを使用した。
from bs4 import BeautifulSoup from urllib.request import urlopen import re html = urlopen("https://ja.wikipedia.org/wiki/google") bsObj = BeautifulSoup(html.read()) print(bsObj.title)
実行すると以下のようになる。
タイトルタグを除去できていないため修正する必要がある。