準(zhǔn)備
python 2.7.11
? ? ? $pip install requests
? ? ? $pip install beautifulsoup4
Google Chrome
獲取圖片的CSS選擇器的規(guī)則
? chrome來訪問網(wǎng)頁?http://jandan.net/ooxx , 然后打開開發(fā)者工具菜單 -> 更多工具 -> 開發(fā)者工具
1
2
3
右邊神器中就會(huì)出現(xiàn)我們所需要的img標(biāo)簽,查看之前最后一個(gè)以#comments開頭的標(biāo)簽,它包含了所有img的子標(biāo)簽。
4
import requests
from bs4 import BeautifulSoup
res = requests.get('http://jandan.net/ooxx')
html = BeautifulSoup(res.text)forindex,eachin enumerate(html.select('#comments img')):
withopen('{}.jpg'.format(index),'wb') as jpg:
jpg.write(requests.get(each.attrs['src'], stream=True).content)
$python demo.py?
快去看看,保存demo.py 的文件下有什么吧.