外部URLをフェッチ

□未翻訳

□翻訳中

□翻訳完了 (Yota Ichino)

■レビュー(Omi Chiba)

外部URLをフェッチ

Pythonには、URLフェッチするためのライブラリurllibが同梱されています。

Python includes the urllib library for fetching urls:

1.

2.

import urllib

page = urllib.urlopen('http://www.web2py.com').read()

多くの場合は大丈夫ですが、urllibモジュールは、Google App Engine上では動作しません。Googleは、GAE用に、URLをダウンロードするための異なるAPIを提供します。あなたのコードを移植しやすくするために、web2pyは、他のPython環境だけでなくGAEでも動くfetch関数を同梱しています:

This is often fine, but the urllib module does not work on the Google App Engine. Google provides a different API for downloading URLs that works on GAE only. In order to make your code portable, web2py includes a fetch function that works on GAE as well as other Python installations:

1.

2.

from google.tools import fetch

page = fetch('http://www.web2py.com')