転載学習:https://www.cnblogs.com/alex3714/articles/8359404.html
、ライブラリー導入を要求します
リクエストはApache2のは、オープンソースのライブラリをライセンスHTTPプロトコルを使用して、書かれたPython言語ベースのurllibはを使用しています。
二つは、基本的なライブラリの使用を要求します
インポートが要求 応答を = requests.get(" https://www.baidu.com " ) プリント(response.status_code) プリント(response.text) プリント(response.cookies) プリント(response.content)
直接response.textが文字化けしている場合、以下のように、多くの場合、サイトに問題があるでしょう、頻繁に使用する溶液は、次のとおりです。
インポート要求 応答 = requests.get(" https://www.baidu.com " )
:方法1 プリント(response.content.decode(" UTF-8 ")) # 方法2: response.encodingを = " UTF-8 「 印刷(response.text)
三、リクエスト要求
インポート要求が requests.post(" http://httpbin.org/post " ) requests.put(" http://httpbin.org/put " ) requests.delete(" http://httpbin.org/delete " ) requests.head(" http://httpbin.org/get " ) requests.options(" http://httpbin.org/get ")