本文共 653 字,大约阅读时间需要 2 分钟。
1.获取返回值
1 2 3 4 5 6 7 8 9 | [root@bogon ~] # cat request.py #!/usr/bin/env python #encoding:utf-8 import requests r = requests.get( "http://www.baidu.com" ) print r [root@bogon ~] # python request.py <Response [ 200 ]> [root@bogon ~] # |
2.get带有参数的url
1 2 3 4 5 6 7 8 9 10 | [root@bogon ~] # cat request1.py #!/usr/bin/env python #encoding:utf-8 import requests payload = { "key1" : "value1" , "key2" : "value2" } r = requests.get( "http://www.baidu.com" , params=payload) print r.url [root@bogon ~] # python request1.py http: //www .baidu.com/?key2=value2&key1=value1 [root@bogon ~] # |