0x00 case Crawl All pictures of a page in the blog park and download to local
A continuous week of Python, harvest a lot, mainly to exercise their temper ... Don't say a word, put on the script first
#Coding:utf-8ImportUrllib2ImportReurl="https://www.cnblogs.com/peterpan0707007/p/7620048.html"Headers={'user-agent':'mozilla/5.0 (Windows NT 10.0; WOW64; rv:59.0) gecko/20100101 firefox/59.0'}req=urllib2. Request (url,headers=headers) Resp=Urllib2.urlopen (req). Read ()Data=re.compile (R ' Http:.+\.png '). FindAll (resp) #正则匹配png图片#Print Data forIinchData:with Open ('Result.txt','a') as Fw:fw.write (i+'\ n') with open ('Result.txt','R') as fr: forLineinchfr.readlines (): Response=Urllib2.urlopen (line). read () filename=line.strip ('\ n'). Split ('-') [2]+'. PNG'with open (filename,'WB') as Fw:fw.write (response)Print ' Done'
Run results
Python Learning simple web crawler