tadashi000000

theme:

HTTPライブラリRequestsの利用

summary:

HTTPライブラリRequestsを利用してhtmlを取得するpythonプログラム

points:

・エンコーディングに注意

environment:

python 3.6.2

requests 2.18.4

beautifulsoup4 4.6.0

chardet 3.0.4

※スタートメニュー>Anaconda3(64-bit)>Anaconda Navigator>Environments>installed で確認

※すべてAnacondaに同梱されており改めてインストールする必要はなし

date:
reference:

RequestsとBeautiful Soupでのスクレイピング時に文字化けを減らす

http://orangain.hatenablog.com/entry/encoding-in-requests-and-beautiful-soup
Python:

import requests
from bs4 import BeautifulSoup
r = requests.get("http://tadashi0vi.html.xdomain.jp/test014.html")
soup = BeautifulSoup(r.content, 'html.parser')
print(soup)
output:

当該ページのhtmlが出力される