Python爬蟲-request的用法

來源:互聯網
上載者:User

標籤:res   mozilla   登陸驗證   win   會話   git   ssi   二進位   agent   

import requestsif __name__ == ‘__main__‘:    #基本用法    #response = requests.get("http://httpbin.org/get")    #print(response.text)    #帶參數的get    #data = {    #    "name":"wu",    #    "age":21    #}    #response = requests.get("http://httpbin.org/get",params=data)    #print(response.text)    #解析json    #print(response.json)    #擷取二進位資訊    #response = requests.get("http://github.com/favicon.ico")    #print(response.content)    #with open("favicon.ico","wb") as f:    #    f.write(response.content)    #    f.close()    #添加headers    #headers = {    #    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64)"    #}    #response = requests.get("http://www.zhihu.com/explore",headers = headers)    #print(response.text)    #post請求    #data = {    #    "name":"wu",    #    "age":21    #}    #headers = {    #    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64)"    #}    #response = requests.post("http://www.httpbin.org/post",data = data,headers = headers)    #狀態代碼判斷    #response = requests.get("http://www.baidu.com")    #exit() if not response.status_code == requests.codes.ok else print("OK")    #檔案上傳    #...    #cookie    #...    #會話維持(類比登陸驗證)    #s = requests.Session() #相當於在一個瀏覽器中    #s.get("http://httpbin.org/cookies/set/number/123456789")    #response = s.get("http://httpbin.org/cookies")    #print(response.text)    #認證驗證(https)    #response = get("http://www.12306.cn",verify = False)    #print(response.status_code)    #指定認證...    #代理    #proxies = {    #    "http":    #    "https"    #}    #response = requests.get("http://www.12306.cn",proxies = proxies)    #逾時設定    #認證設定

Python爬蟲-request的用法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.