python の http.client で html をダウンロードする方法のメモ。
requests.get(url) で簡単に html をダウンロードできましたが、
url にポート番号を入れたらダウンロードできなかったので、
http.client を使ってみました。
requests.get(url) で簡単に html をダウンロードできましたが、
url にポート番号を入れたらダウンロードできなかったので、
http.client を使ってみました。
import http.client host = 'localhost' # ホスト名 port = 5104 # ポート番号 request_path = '/index' # パス conn = http.client.HTTPConnection(host, port) conn.request('GET', request_path) response = conn.getresponse() conn.close() html = response.read().decode('utf-8') print(html)