python爬蟲知識點總結(二)爬蟲的基本原理


一、什么是爬蟲?

  答:請求網頁並提取數據的自動化程序。

二、爬蟲的基本流程

 

 

三、什么是Request和Response?

 

  1、Request

 

  2、Response

 

四、能抓取怎樣的數據

五、解析方式

 

六、怎么解決JavaScript渲染的問題?

 

七、怎么保存數據?

 

 測試代碼:

import requests
response = requests.get('http://www.baidu.com')
print(response.text)
print(response.headers)
print(response.status_code)

headers = {'User-Agent':' Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.75 Mobile Safari/537.36}
response = requests.get('http://www.baidu.com',headers=headers)
print(response.status_code)

response = requests.get('https://gss0.bdstatic.com/5bd1bjqh_Q23odCf/static/newtab/img/fetch_ing_8_0.png')
print(response.content)

with open('/var/tmp/1.png','wb')  //寫到本地的文件
  fwrite(response.content)
  f.close()

  

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM