今治イベント情報を取得(相対アドレスの変換)
import urllib.request from bs4 import BeautifulSoup from urllib.parse import urljoin url = "http://www.city.imabari.ehime.jp/event/" html = urllib.request.urlopen(url).read() soup = BeautifulSoup(html, from_encoding='cp932') for event_ichiran in soup.find_all("dl",{"class":"event_ichiran"}): for event in event_ichiran.find_all("dd"): print(event.get_text().strip()) link = event.find("a") if link: #相対アドレスから絶対アドレスに変換 print(urljoin('http://www.islands.ne.jp/imabari/',link.get('href'))) print("<hr>")