リダイレクトされるURLにアクセスするためのPythonコード。
- 標準のhttp.clientでは、リダイレクトに対応できない
- urllibは標準ライブラリに含まれる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib.request | |
def urllibRequest(): | |
url="https://xxxxxxxxxxxx" | |
response = urllib.request.urlopen(url) | |
content = response.read() | |
if content is not None: | |
response = { | |
'statusCode': 200, | |
'body': content | |
} | |
else: | |
response = { | |
'statusCode': 500, | |
'body': 'Failed to retrieve URL content' | |
} | |
return response |
0 件のコメント:
コメントを投稿