Learning + interest combined to crawl pictures (feeling also OK, is a bit slow, 135 pictures took 37 seconds, another day with multi-threaded try):
#encoding =utf-8
Import Requests,re,os,time
From BS4 import BeautifulSoup
Class Stone ():
#获取照片url
def get_url (self):
#创建图片链接列表
pictures = []
url = ' http://hs.blizzard.cn/article/16/11477 '
urls = requests.get (URL)
t = urls.content
Soup =beautifulsoup (T, "Html.parser")
#获取所有链接的元素
Pic_div = Soup.find_all (' img ', style= "border:none; box-shadow:none;")
#循环将图片链接加到pictures列表中
For I in Pic_div:
PNG_RL = i["src"]
Pictures.append (PNG_RL)
return pictures
#下载图片
def download (self,pictures):
t = 1 #用数字给文件命名
For I in pictures:
#获取当前文件路径, create a folder to store your pictures in advance. Stone
With open (OS.GETCWD () + "\\stone\\" + "%d.png"%t, ' WB ') as F:
F.write (Requests.get (i). Content)
T+=1 #每过一张文件名就加1
t = Stone ()
Pictures = T.get_url ()
Print U "Start time:" +time.strftime ("%y-%m-%d%h:%m:%s", Time.localtime (Time.time ()))
T.download (Pictures)
Print u "Download Complete"
Print U "End Time:" +time.strftime ("%y-%m-%d%h:%m:%s", Time.localtime (Time.time ()))
Automatically download the latest new card from the official website with Python