1. 程式人生 > 實用技巧 >python爬蟲-爬取百度圖片

python爬蟲-爬取百度圖片

python爬蟲-爬取百度圖片(轉)
#!/usr/bin/python
# coding=utf-8
# 作者 :Y0010026
# 建立時間 :2018/12/16 16:16
# 檔案 :spider_04.py
# IDE :PyCharm

# 爬取百度圖片(GET方式爬取Ajax資料)
import urllib2

url = 'http://image.baidu.com/search//acjson?tn=resultjson_com&ipn=rj&ct=201326592&is=&fp=' \
'result&queryWord=%E9%9D%92%E6%98%A5%E5%A6%B9%E5%AD%90%E5%9B%BE&cl=2&lm=-1&ie=utf-8&oe=' \

'utf-8&adpicid=&st=&z=&ic=&word=%E9%9D%92%E6%98%A5%E5%A6%B9%E5%AD%90%E5%9B%BE&s=&se=&tab=&width=' \
'&height=&face=&istype=&qc=&nc=&fr=&pn=30&rn=30&gsm=1e&1502192101260='

# 請求頭描述資訊
header = {
'User-Agent': 'Mozilla/5.0(WindowsNT6.1;rv:2.0.1)Gecko/20100101Firefox/4.0.1'

}
# 包裝請求物件
requset = urllib2.Request(url, headers=header)
# 根據請求物件傳送資料請求,獲取伺服器返回的響應物件
response = urllib2.urlopen(requset)
# 獲取響應物件中的資料
content = response.read()
# 將獲取的資料儲存在檔案中
with open('qing.json', 'w') as f:
f.write(content)
原文連結:https://www.cnblogs.com/huangjiaxiaoluobo/p/10126963.html