龙空技术网

wallpaper壁纸超清大图Python爬虫程序

那一棵梧桐树 109

前言:

目前你们对“python主题壁纸”可能比较着重,小伙伴们都需要学习一些“python主题壁纸”的相关资讯。那么小编在网络上汇集了一些有关“python主题壁纸””的相关文章,希望同学们能喜欢,朋友们快快来了解一下吧!

地址:

修改之前的爬虫文件,爬取2048 x 1152壁纸,可以了

import requestsimport reimport osfrom bs4 import BeautifulSoup url = ';head = {    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36'}response = requests.post(url,headers=head)page_txt = response.textex='<div class="thumb">.*?<img src="(.*?)" alt.*?</div>'img_list = re.findall(ex,page_txt,re.S)imgpath = './img/'if not os.path.exists(imgpath):    os.mkdir(imgpath)for img in img_list:    img_name = img.split('/')[-1]    img_path = imgpath + img_name    big_image = ';+img_name.split('-')[0] +'-wallpapers'+'.html'    print("bigimage: " + big_image)    img_response = requests.post(big_image,headers=head)    page_text = img_response.text    ex='<div align="center" class="picture_wrapper_details".*?<img src="(.*?)" alt.*?</div>'        #大图标地址    big_image_list = re.findall(ex,page_text,re.S)    #  tittle = "HD 16:9 2048 x 1152 wallpaper"    soup = BeautifulSoup(page_text,'html.parser')    # wallpaperlist = soup.find_all('a',title='HD 16:9 2048 x 1152 wallpaper')    title = soup.find_all('a',title='HD 16:9 2048 x 1152 wallpaper')    #[<a href="/download/basim___assassins_creed_mirage_2023_video_game-wallpaper-2048x1152.jpg" target="_self" title="HD 16:9 2048 x 1152 wallpaper">2048x1152</a>]    print(title[0].get('href'))    wallpaperUrl = ';+title[0].get('href')#壁纸地址    #            if not os.path.exists(img_path):            bigimg_response = requests.post(wallpaperUrl,headers=head)            with open(img_path,'wb') as f:                f.write(bigimg_response.content)                print(f'save {img_path}')    else:        print('{img_path} already exists')        # 下载图标的    # for bigimg in big_image_list:    #     if not os.path.exists(img_path):    #         bigimg_response = requests.post(bigimg,headers=head)    #         with open(img_path,'wb') as f:    #             f.write(bigimg_response.content)    #             print(f'save {img_path}')    #     else:    #         print('{img_path} already exists')       # print(img_list)

标签: #python主题壁纸