Skip to content

Commit

Permalink
Merge pull request #129 from pyconjp/ISSHA-1456-update-text
Browse files Browse the repository at this point in the history
ISSHA-1456 テキストを更新
  • Loading branch information
takanory committed Nov 16, 2018
2 parents e76ad7f + 2b6e987 commit 82d5cdc
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 55 deletions.
22 changes: 11 additions & 11 deletions source/textbook/1_install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,23 @@ macOSの場合
-------------------------------------
macOSでPythonを利用する場合は、Pythonの公式サイトで配布されているビルド済みのパッケージをインストールします。

「 `Python Release Python 3.6.6 <https://www.python.org/downloads/release/python-366/>`_ 」をブラウザで開きます。
「 `Python Release Python 3.6.7 <https://www.python.org/downloads/release/python-367/>`_ 」をブラウザで開きます。
以下のいずれかをダウンロードして実行し、Pythonをインストールします。

- OS X 10.9以降: `macOS 64-bit installer <https://www.python.org/ftp/python/3.6.6/python-3.6.6-macosx10.9.pkg>`_
- Mac OS X 10.6以降: `macOS 64-bit/32-bit installer <https://www.python.org/ftp/python/3.6.6/python-3.6.6-macosx10.6.pkg>`_
- OS X 10.9以降: `macOS 64-bit installer <https://www.python.org/ftp/python/3.6.7/python-3.6.7-macosx10.9.pkg>`_
- Mac OS X 10.6以降: `macOS 64-bit/32-bit installer <https://www.python.org/ftp/python/3.6.7/python-3.6.7-macosx10.6.pkg>`_

詳しくはPythonの公式ドキュメントの「 `MacintoshでPythonを使う <https://docs.python.org/ja/3/using/mac.html>`_ 」を参考にしてください。

インストールが完了したらPythonのバージョンが3.6.6になっていることを確認します:numref:`check-version-mac`)。
インストールが完了したらPythonのバージョンが3.6.7になっていることを確認します:numref:`check-version-mac`)。

.. _check-version-mac:

.. code-block:: bash
:caption: Pythonのバージョンを確認
$ python3.6 -V
Python 3.6.6
$ python3 -V
Python 3.6.7
.. index::
single: Install; Windows
Expand All @@ -82,11 +82,11 @@ Windowsの場合

WindowsでPythonを利用する場合は、Pythonの公式サイトで配布されているWindowsインストーラを利用します。

「 `Python Release Python 3.6.6 <https://www.python.org/downloads/release/python-366/>`_ 」をブラウザで開きます。
「 `Python Release Python 3.6.7 <https://www.python.org/downloads/release/python-367/>`_ 」をブラウザで開きます。
OSによって以下のいずれかのインストーラーをダウンロードし、ウィザードに従ってインストールします。

- 64ビット版: `Windows x86-64 executable installer <https://www.python.org/ftp/python/3.6.6/python-3.6.6-amd64.exe>`_
- 32ビット版: `Windows x86 executable installer <https://www.python.org/ftp/python/3.6.6/python-3.6.6.exe>`_
- 64ビット版: `Windows x86-64 executable installer <https://www.python.org/ftp/python/3.6.7/python-3.6.7-amd64.exe>`_
- 32ビット版: `Windows x86 executable installer <https://www.python.org/ftp/python/3.6.7/python-3.6.7.exe>`_

この時、「Add Python 3.6 to PATH」にチェックを入れておきましょう。自動的に必要な環境変数が設定されます(:numref:`windows-install`)。

Expand All @@ -100,15 +100,15 @@ OSによって以下のいずれかのインストーラーをダウンロード
.. index::
single: Install; Linux

インストールが完了したらPythonのバージョンが3.6.6になっていることを確認します:numref:`check-version-win`)。
インストールが完了したらPythonのバージョンが3.6.7になっていることを確認します:numref:`check-version-win`)。

.. _check-version-win:

.. code-block:: doscon
:caption: Pythonのバージョンを確認
C:\Users\user>python -V
Python 3.6.6
Python 3.6.7
Linux(Ubuntu Server)の場合
-------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions source/textbook/2_intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ Pythonインタープリタ

さっそくPythonで遊んでみましょう。

ターミナル(WindowsではPowerShell)を立ち上げて ``python`` (macOS、Linuxの場合はpython3)と入力し、Pythonインタープリタを対話モードで起動しましょう(:numref:`python-interpreter`)。
ターミナル(WindowsではPowerShell)を立ち上げて ``python`` (macOS、Linuxの場合は ``python3``)と入力し、Pythonインタープリタを対話モードで起動しましょう(:numref:`python-interpreter`)。

.. _python-interpreter:

.. code-block:: bash
:caption: Pythonインタープリタの起動
$ python3
Python 3.6.6 (v3.6.6:4cf1f54eb7, Jun 26 2018, 19:50:54)
Python 3.6.7 (v3.6.7:6ec5cf24b7, Oct 20 2018, 03:02:14)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
Expand Down
14 changes: 7 additions & 7 deletions source/textbook/3_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@ Pythonのスライスを使えば、 :numref:`slice-string` のように、2、3
.. index:: in()
single: String; in()

文字列の有無(in
------------------
文字列の有無(in演算子
------------------------

文字列中にある文字列が存在するかどうかを調べるには、 ``in`` を使います:numref:`guide-in`)。
文字列中にある文字列が存在するかどうかを調べるには、 ``in`` 演算子を使います:numref:`guide-in`)。

.. _guide-in:

Expand All @@ -311,8 +311,8 @@ Pythonのスライスを使えば、 :numref:`slice-string` のように、2、3
.. index:: split()
single: String; split()

文字列の分割(.split()メソッド)
----------------------------------
文字列の分割(.split()メソッド)
--------------------------------

文字列を分割するには、 ``.split()`` メソッドを使います。

Expand All @@ -331,8 +331,8 @@ Pythonのスライスを使えば、 :numref:`slice-string` のように、2、3
.. index:: join()
single: String; join()

区切り文字による文字列の結合(.join()メソッド)
-------------------------------------------------
区切り文字による文字列の結合(.join()メソッド)
-----------------------------------------------

文字列を区切り文字で結合するには、 ``.join()`` メソッドを使います。

Expand Down
20 changes: 10 additions & 10 deletions source/textbook/4_collections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Pythonのデータ型のうち、複数のデータ型をひとまとめにし
single: Collection; for

for文
---------
-----

リストは、 ``for`` 文の繰り返し用変数として使えます(:numref:`for-list`)。

Expand Down Expand Up @@ -82,7 +82,7 @@ for文
single: Collection; append()

要素の追加
-----------------
----------

リストに要素を追加するには、 ``.append()`` メソッドを使います。
``.append()`` メソッドはリストの末尾に要素を追加します(:numref:`list-append`)。
Expand Down Expand Up @@ -112,7 +112,7 @@ for文
single: Collection; comprehension

リスト内包表記
----------------
--------------
リスト内包表記はリストの定義方法の1つです。
比較的複雑なリストの定義を、シンプルに記述できます。

Expand Down Expand Up @@ -161,7 +161,7 @@ for文
single: Collection; substitute

複数変数への代入
--------------------------
----------------

リストのようなシーケンス型から他のデータ型に値を代入する際、複数の変数への代入を一度に行えます(:numref:`multi-substitute`)。

Expand Down Expand Up @@ -194,7 +194,7 @@ for文
single: Collection; tuple

タプル(tuple)
========================
===============

タプルはリストと同じコレクションの1つです。

Expand Down Expand Up @@ -255,7 +255,7 @@ for文
single: Collection; immutable

リストとの違いと使いどころ
------------------------------
--------------------------

リストと違いタプルは不変(immutable)な値です。
リストの ``.append()`` のような破壊的な操作は存在しません。
Expand Down Expand Up @@ -300,7 +300,7 @@ for文
single: Collection; dict

辞書(dict)
==============
============

辞書もリスト、タプルと同じコレクションです。

Expand Down Expand Up @@ -342,10 +342,10 @@ for文
.. index:: in
single: Collection; in

in
----
in演算子
--------

辞書内にキーが存在しているかどうかを調べるには、 ``in`` を使います:numref:`dict-in`)。
辞書内にキーが存在しているかどうかを調べるには、 ``in`` 演算子を使います:numref:`dict-in`)。

.. _dict-in:

Expand Down
39 changes: 19 additions & 20 deletions source/textbook/6_venv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,29 @@ venvはプロジェクトごとに隔離されたPythonの仮想環境(Virtual E

以前は pyvenvスクリプトを利用したPython実行環境の作成方法を紹介していました。

ですが、Python3.6 から pyvenvスクリプトが非推奨となり将来的に削除されるので一部説明を変更をいたしました。
ですが、Python 3.6 から pyvenvスクリプトが非推奨となり将来的に削除されるので一部説明を変更をいたしました。
今後は「python -m venv」を利用するようにしてください。

pyvenvスクリプトが廃止になった経緯は下記URLを参照してください。

https://docs.python.org/ja/3/whatsnew/3.6.html#id8

.. admonition:: コラム: condaの場合

`Anaconda <https://www.continuum.io/downloads>`_ を使っている場合は **pip** 、 **venv** の代わりに `Conda <http://conda.pydata.org/docs/>`_ というパッケージ管理ツールを使用します。

condaではそれぞれ以下のコマンドで、サードパーティー製パッケージのインストール、環境の作成、有効化、無効化が行えます。

.. code-block:: sh
:caption: conda コマンドの例
$ conda create --name env python # 環境を作成
$ source activate env # 環境の有効化
(env) $ conda install requests # パッケージのインストール
(env) $ source deactivate # 環境の無効化
venv環境の作成
----------------
--------------

venv環境を作成します。

Expand Down Expand Up @@ -152,8 +165,8 @@ Windowsの場合はスクリプトを実行します( :numref:`venv-activate-w
.. code-block:: sh
:caption: パッケージのインストール
(env)$ pip install requests
(env)$ python
(env) $ pip install requests
(env) $ python
>>> import requests
>>> # requestsがインポートできる
Expand All @@ -164,7 +177,7 @@ Windowsの場合はスクリプトを実行します( :numref:`venv-activate-w
.. index:: deactivate

venv環境の無効化
------------------
----------------
``venv`` 環境を無効化(deactivate)するには、 ``deactivate`` コマンドを実行します(:numref:`venv-deactivate`)。

無効化した後、元の環境で ``requests`` をインポートするとエラーとなり、 ``venv`` 環境でのみ ``requests`` がインストールされていることがわかります。
Expand All @@ -174,7 +187,7 @@ venv環境の無効化
.. code-block:: sh
:caption: venv環境を無効化
(env)$ deactivate
(env) $ deactivate
$
$ python
>>> import requests
Expand Down Expand Up @@ -230,20 +243,6 @@ venv環境の無効化

.. index:: conda

conda の場合
============
`Anaconda <https://www.continuum.io/downloads>`_ を使っている場合は **pip** 、 **venv** の代わりに `Conda <http://conda.pydata.org/docs/>`_ というパッケージ管理ツールを使用します。

condaではそれぞれ以下のコマンドで、サードパーティー製パッケージのインストール、環境の作成、有効化、無効化が行えます。

.. code-block:: sh
:caption: conda コマンドの例
$ conda create --name env python # 環境を作成
$ source activate env # 環境の有効化
(env) $ conda install requests # パッケージのインストール
(env) $ source deactivate # 環境の無効化
まとめ
=======

Expand Down
20 changes: 15 additions & 5 deletions source/textbook/7_scraping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@


環境構築
=====================
========

前章の「 :ref:`about-venv` 」を参考に、venvモジュールを利用して、スクレイピング用のvenv環境を構築します。
venv環境を ``activate`` コマンドで有効にし、スクレイピングに使用するRequestsとBeautiful Soup 4を ``pip`` コマンドでインストールします。

.. code-block:: sh
:caption: スクレイピング用のvenv環境を構築
:caption: スクレイピング用のvenv環境を構築(macOS、Linux)
$ mkdir scraping
$ cd scraping
Expand All @@ -29,11 +29,21 @@ venv環境を ``activate`` コマンドで有効にし、スクレイピング
(env) $ pip install requests
(env) $ pip install beautifulsoup4
.. code-block:: sh
:caption: スクレイピング用のvenv環境を構築(Windows)
> mkdir scraping
> cd scraping
> python -m venv env
> env\Scripts\Activate.ps1
(env) > pip install requests
(env) > pip install beautifulsoup4
.. index:: Requests

Requests
--------
:URL: http://docs.python-requests.org/en/master/
:URL: http://docs.python-requests.org/

Requests について簡単に紹介します。
Requests はウェブサイトにアクセスしてHTMLなどのデータを取得するためのライブラリです。
Expand Down Expand Up @@ -344,15 +354,15 @@ Beautiful Soup 4の主な使い方
5
まとめ
==========
======
本節では、Pythonでスクレイピングをする方法を解説しました。

RequestsとBeautiful Soup 4を使いこなすことにより、さまざまなウェブサイトから情報を取得できるようになります。

なお、短時間にWebサイトに大量にアクセスをすると迷惑となるので、そういうことがないようにプログラムを実行するときには注意してください。

参考書籍
==========
========
Pythonでのスクレイピングについてもいくつか書籍が出ています。

- `PythonによるWebスクレイピング <https://www.oreilly.co.jp/books/9784873117614/>`_
Expand Down

0 comments on commit 82d5cdc

Please sign in to comment.