看到必应美图没有水印了,就想着可以拿来做壁纸了,(早想这么干了)python也是现学现用的,写得很烂,只求能用程度
用python的BeautifulSoup爬出来链接,再用urllib下载文件
import urllib.request
import urllib3
import os
from bs4 import BeautifulSoup
#下载进度显示
def Schedule(a,b,c):
per = 100.0 * a * b / c
if per > 100.0 :
print('success')
#获取网页流
URL='http://cn.bing.com'
http=urllib3.PoolManager()
bing=http.request('GET',URL)
#解析出文件地址
soup=BeautifulSoup(bing.data,"html.parser")
imgbg=soup.select('#bgImg')[0]
fileULR=URL+imgbg.get('src')
fileName=fileULR.split('/')[-1]
#开始下载文件
urllib.request.urlretrieve(fileULR,'../Pictures/Wallpaper/'+fileName,Schedule)
#保存url到日志文件
open('./url.txt','a',encoding='utf-8').write(fileULR+'\n')
2019.1.23更新(原标签节点已消失,更新其他标签节点)
import urllib.request
import urllib3
import os
from bs4 import BeautifulSoup
def Schedule(a,b,c):
per = 100.0 * a * b / c
if per > 100.0 :
print('success')
URL='http://cn.bing.com'
http=urllib3.PoolManager()
bing=http.request('GET',URL)
soup=BeautifulSoup(bing.data,"html.parser")
imgbg=soup.select('#bgLink')[0]
fileULR=URL+imgbg.get('href')
fileName=fileULR.split('/')[-1]
urllib.request.urlretrieve(fileULR,'C:/Users/Hyz/OneDrive/Wallpaper/'+fileName,Schedule)
open('./url.txt','a',encoding='utf-8').write(fileULR+'\n')
2019.1.28更新,多加国际版搜索壁纸
import urllib.request
import urllib3
import os
from bs4 import BeautifulSoup
#忽略证书验证
urllib3.disable_warnings()
def Schedule(a,b,c):
per = 100.0 * a * b / c
if per > 100.0 :
print('100% success')
else:
sys.stdout.write(str(format(per,".1f"))+'%\r')#占行数字进度效果
sys.stdout.flush()
URL='http://cn.bing.com'
def bingImg(url):
http=urllib3.PoolManager()
bing=http.request('GET',url)
soup=BeautifulSoup(bing.data,"html.parser")
imgbg=soup.select('#bgLink')[0]
fileULR=URL+imgbg.get('href')
fileName=fileULR.split('/')[-1]
urllib.request.urlretrieve(fileULR,'C:/Users/Hyz/OneDrive/Wallpaper/'+fileName,Schedule)
open('./url.txt','a',encoding='utf-8').write(fileULR+'\n')
bingImg(URL)
bingImg('https://cn.bing.com/?FORM=BEHPTB&ensearch=1')
2019.3.10更新
import urllib3
import os
import sys
from urllib import request,parse
from bs4 import BeautifulSoup
#忽略证书验证
urllib3.disable_warnings()
def Schedule(a,b,c):
per = 100.0 * a * b / c
if per > 100.0 :
print('100% success')
else:
sys.stdout.write(str(format(per,".1f"))+'%\r')#占行数字进度效果
sys.stdout.flush()
URL='http://cn.bing.com'
def bingImg(url):
http=urllib3.PoolManager()
bing=http.request('GET',url)
soup=BeautifulSoup(bing.data,"html.parser")
imgbg=soup.select('#bgLink')[0]
fileULR=URL+imgbg.get('href')
#解析URL参数得出文件名
fileName="".join(parse.parse_qs(parse.urlparse(fileULR).query)['id'])
request.urlretrieve(fileULR,'C:/Users/Hyz/OneDrive/Wallpaper/'+fileName,Schedule)
open('./url.txt','a',encoding='utf-8').write(fileULR+'\n')
bingImg(URL)
#bingImg('https://cn.bing.com/?FORM=BEHPTB&ensearch=1')