python3抓图学习-百度贴吧

# coding=utf-8

from bs4 import BeautifulSoup
import urllib.request
import os
import time def downlaodimg(url): os.chdir(os.path.join(os.getcwd(), 'photos'))
t = 1 # 记录图片张数 html_doc = urllib.request.urlopen(url).read().decode('utf-8')
soup = BeautifulSoup(html_doc, "lxml") for myimg in soup.find_all('img', class_='BDE_Image'):
pic_name = str(time.time()) + '.jpg'
img_src = myimg.get('src')
urllib.request.urlretrieve(img_src, pic_name)
print("Success!" + img_src)
t += 1 downlaodimg("https://tieba.baidu.com/p/2772656630")
上一篇:Python设计模式 - UML - 通信图(Communication Diagram)


下一篇:部署图 Deployment Diagram