LoginSignup
2
3

More than 5 years have passed since last update.

Python&Macでスクレイピングをはじめようとしたらつまづいたこと

Last updated at Posted at 2018-12-02

0.はじめに

Pythonをはじめた人なら誰もが興味をもつスクレイピング。
やってみたい記事がたくさんありますよね。

と思いきや、環境設定でつまづく人も多いハズ。私もその一人です。
私のつまづいたことと解決方法を共有します。

1.Macではデフォルトで2.xのPythonが入っているがゆえにurlopenが使えない

【つまづいたところ】 "NameError: name 'urlopen' is not defined"というエラーがでる
【解決方法】 Pythonを使っているとバージョンの違いに苦しめられることが多いです。デフォルトのエディタのPythonの設定を確認しましょう。

私の場合は3.xを使いたいので、過去のQiitaの記事 atomでpython3を実行する
がとても参考になりました。

参考)NameError: name 'urlopen' is not defined

2.証明書エラー

【つまづいたポイント】 "CERTIFICATE_VERIFY_FAILED error"というエラーが出る
【解決方法】 アプリケーションフォルダにあるPythonフォルダで"Install Certificates.command"を実行してあげましょう。以下のような実行結果が出るはずです。

参考)Scraping: SSL: CERTIFICATE_VERIFY_FAILED error

##実行結果
 -- pip install --upgrade certifi
Requirement already up-to-date: certifi in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (2018.11.29)
 -- removing any existing file or link
 -- creating symlink to certifi certificate bundle
 -- setting permissions
 -- update complete
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
Deleting expired sessions...none found.
[プロセスが完了しました]
```![error]()

他にもなにかあれば更新していきます。

2
3
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
3