音乐播放器
陈鑫磊的博客
 
文章 标签
4

Copyright © 2020-2021 陈鑫磊
RSS 随机音乐
北京时间: : )正在加载....
Powered by Gridea | Theme: Fog
载入天数...
载入时分秒...
总访问量:  |   访问人数:

必应壁纸下载代码

  热度: loading...

是网上搜的,经我修改过的python3.6
多线程版下载地址
普通版下载地址

import  re
import os
import requests
from time import sleep

headers = {
    "User-Agent": ("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) "
                   "Gecko/20100101 Firefox/64.0")
}

def get_index(resolution, index=1):
    url = f"https://bing.ioliu.cn/ranking?p={index}"
    res = requests.get(url, headers=headers)
    urls = re.findall('pic=(.*?)\\.jpg', res.text)
    _old_resolution = urls[1].split("_")[-1]
    return {url.split("/")[-1].replace(_old_resolution, resolution): url.replace(_old_resolution, resolution) + ".jpg"
            for url in urls}

def download_pic(pics):
    if os.path.exists('必应壁纸'):
        pass
    else:
        os.mkdir('必应壁纸')
        print('目录创建成功')
    try:
        for pic_name, pic_url in pics.items():
            res = requests.get(pic_url, headers=headers)
            with open(f"必应壁纸\\{pic_name}.jpg", mode="wb") as f:
                f.write(res.content)
            print(f"{pic_name} 下载完成")
    except Exception as e:
        print("下载出错", e)

def input_index():
    while True:
        sleep(0.1)
        index = input("请输入要下载的页数:")
        try:
            if index == "Q":
                exit()
            index = int(index)
            return index
        except ValueError:
            print("请输入数字, 或输入Q退出!")

def main():
    index = input_index()
    i = 1
    while i <= index:
        print(f"当前第{i}页,共需要下载{index}页")
        pics = get_index("1920x1080", i)
        download_pic(pics)
        i += 1
    print("下载完成,将在3秒后关闭...")
    sleep(1)
    print("2")
    sleep(1)
    print("1")
    sleep(1)
    print("0")

if __name__ == '__main__':
    main()

2号防封ip

import  re
import os
import requests
import time
from time import sleep

headers = {
    "User-Agent": ("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) "
                   "Gecko/20100101 Firefox/64.0")
}

def get_index(resolution, index=1):
    url = f"https://bing.ioliu.cn/ranking?p={index}"
    res = requests.get(url, headers=headers)
    urls = re.findall('pic=(.*?)\\.jpg', res.text)
    _old_resolution = urls[1].split("_")[-1]
    return {url.split("/")[-1].replace(_old_resolution, resolution): url.replace(_old_resolution, resolution) + ".jpg"
            for url in urls}

def download_pic(pics):
    if os.path.exists('必应壁纸'):
        pass
    else:
        os.mkdir('必应壁纸')
        print('目录创建成功')
    try:
        for pic_name, pic_url in pics.items():
            time.sleep(3)
            res = requests.get(pic_url, headers=headers)
            with open(f"必应壁纸\\{pic_name}.jpg", mode="wb") as f:
                f.write(res.content)
            print(f"{pic_name} 下载完成")
    except Exception as e:
        print("下载出错", e)

def input_index():
    while True:
        sleep(0.1)
        index = input("请输入要下载的页数:")
        try:
            if index == "Q":
                exit()
            index = int(index)
            return index
        except ValueError:
            print("请输入数字, 或输入Q退出!")

def main():
    index = input_index()
    i = 1
    while i <= index:
        print(f"当前第{i}页,共需要下载{index}页")
        pics = get_index("1920x1080", i)
        download_pic(pics)
        i += 1
    print("下载完成,将在3秒后关闭...")
    sleep(1)
    print("2")
    sleep(1)
    print("1")
    sleep(1)
    print("0")

if __name__ == '__main__':
    main()

记得安装python要弄环境变量
使用方法

弄了一个bat文件可以自动安装库有些代码可能多了
python安装方法看安装python部分
多线程版下载地址
普通版下载地址
防封ip版下载地址