import re
import urllib.request
import chardet
from lxml import etree
from bs4 import BeautifulSoup
url = "https://www.qiushibaike.com/pic/"
header = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0",
"Referer":"https://www.qiushibaike.com/"}
def fun(a,b,c):
precent = a*b*1.0/c
if precent>1:
precent = 1
else:
print("%.2f"%(precent*100)+'%')
#a:已经下载的模块
#b:数据块的大小
#c:远程文件的大小
req = urllib.request.Request(url,data = None,headers = header)
ope = urllib.request.urlopen(req)
html = ope.read().decode("utf-8")
reg = r'src="(.+?\.jpeg)"'
img = re.compile(reg)
condition = re.findall(img,html)
for imgurl in condition:
imgurl = 'https:'+imgurl
imgname = imgurl.rsplit('/',1)
urllib.request.urlretrieve(imgurl,imgname[1],fun)
import urllib.request
import chardet
from lxml import etree
from bs4 import BeautifulSoup
url = "https://www.qiushibaike.com/pic/"
header = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0",
"Referer":"https://www.qiushibaike.com/"}
def fun(a,b,c):
precent = a*b*1.0/c
if precent>1:
precent = 1
else:
print("%.2f"%(precent*100)+'%')
#a:已经下载的模块
#b:数据块的大小
#c:远程文件的大小
req = urllib.request.Request(url,data = None,headers = header)
ope = urllib.request.urlopen(req)
html = ope.read().decode("utf-8")
reg = r'src="(.+?\.jpeg)"'
img = re.compile(reg)
condition = re.findall(img,html)
for imgurl in condition:
imgurl = 'https:'+imgurl
imgname = imgurl.rsplit('/',1)
urllib.request.urlretrieve(imgurl,imgname[1],fun)