Python爬虫1-----------placekitten 入门
生活随笔
收集整理的這篇文章主要介紹了
Python爬虫1-----------placekitten 入门
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
常用的urllib庫有三個類:request,parse,error,request主要完成對url的請求,如proxy,opener,urlopen,parse主要完成對html的解析,error負責異常處理。
1 import urllib.request 2 import urllib. 3 4 html=urllib.request.urlopen('http://placekitten.com/500/600') 5 print(type(html)) # 返回的response是一個網頁類型的文件 6 img=html.read() #img是二進制文件 7 print(type(img)) 8 with open("c://spider/cat.jpg",'wb') as f: 9 f.write(img)打開一個url,返回
<class 'http.client.HTTPResponse'>
<class 'bytes'>
轉載于:https://www.cnblogs.com/caojunjie/p/6725907.html
總結
以上是生活随笔為你收集整理的Python爬虫1-----------placekitten 入门的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android 微信支付,body为中文
- 下一篇: Python数据分析第二周总结