Automatically download the latest new card from the official website with Python

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.