准备
python 2.7.11
$pip install requests
$pip install beautifulsoup4
Google Chrome
获取图片的CSS选择器的规则
chrome来访问网页 http://jandan.net/ooxx , 然后打开开发者工具菜单 -> 更多工具 -> 开发者工具
右边神器中就会出现我们所需要的img标签,查看之前最后一个以#comments开头的标签,它包含了所有img的子标签。
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 的文件下有什么吧.