# -*- coding: utf-8 -*-
import urllib
from bs4 import BeautifulSoup
local="D:\\PythonPractice\\WebCrawler\\Photo\\"
def get_content(url):
"""doc."""
html=urllib.urlopen(url)
content=html.read()
html.close()
return content
def get_images(info):
"""
:param info:
:return:
+?匹配一次以上
.除\n以外的任何字符
"""
soup=BeautifulSoup(info,"html.parser")
all_img=soup.find_all('img',class_="BDE_Image")
# print len(all_img)
x=1
for img in all_img:
urllib.urlretrieve(img['src'], local + '%s.jpg' % (x))
x+=1
url="http://tieba.baidu.com/p/4481996921"
info =get_content(url)
print get_images(info)
利用beautifulsoup 取图片
最新推荐文章于 2024-07-22 17:25:13 发布