2
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Python Web スクレイピング

Posted at

スクレイピングを今後勉強していこうと思うので、記事を書いていきたいと思います。
基本的に学習記録です。
こちらの本を参考にさせていただきました。

##スクレイピング(Scraping)とは
スクレイピングとは、webサイトから任意の情報を抽出する技術です。
スクレイピングすることにより、web上で情報を自動収集できます。

つまり、効率的に情報を収集できる技術です。
スクレイピングを調べていると、クローリングという言葉がよく出てきます。
では、クローリングとは何か以下にまとめます。
###クローリングとは
クローリングとは、プログラムがwebサイトを定期的に巡回して、
情報をダウンロードする技術のことです。

定期的に巡回することによって、最新情報を検索することが可能です。
 

#データのダウンロード
##web上の情報を取得する方法

Pythonでは、urllibライブラリを使います。このライブラリを使用すると、HTTPやFTPを利用してデータをダウンロードできます。その中でも、urllib.requestモジュールは、Webサイトにあるデータにアクセスする機能を提供します。

#Webサイトからファイルをダウンロードする方法

download_sample.py
import urllib.request

ulr = "(URL)"
savename = "sample.png"

urllib.request.urlretrieve(url,savename)
print("save the image")

*urlretrieve func : 直接ファイルをダウンロードできる。

#クライアントの接続情報を表示してみる

download.py
import urllib.request

url = "(URL)"
res = urllib.request.urlopen(url)
data = res.read()

#convert binary to string
text = data.decode("utf-8")

簡単ですが、今回はこのぐらいで
随時、勉強したことをアップしていきます。

2
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?