python 爬取美女图片

liftword6个月前 (01-08)技术文章71
import requests
import sys
import io
from bs4 import BeautifulSoup
import time
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='gb18030')
url = 'https://www.umei.cc/bizhitupian/weimeibizhi/'
resp = requests.get(url)
resp.encoding = 'utf-8'
page = BeautifulSoup(resp.text, 'html.parser')
main_div = page.find('div', attrs={'class', 'TypeList'}).find_all("a")
for i in main_div:
    href = i.get("href")
    c_resp = requests.get(href)
    c_resp.encoding = 'utf-8'
    c_page_txt = c_resp.text
    c_page = BeautifulSoup(c_page_txt, 'html.parser')
    p = c_page.find('p', align='center')
    img = p.find("img")
    src = img.get("src")
    img_resp = requests.get(src)
    img_name = src.split("/")[-1]
    with open("img/"+img_name, mode="wb") as f:
        f.write(img_resp.content)

    time.sleep(1)

相关文章

怎么做到的?用python制作九宫格图片,太棒了

1. ? 应用场景 ?当初的想法是:想把一张图切割成九等份,发布到微信朋友圈,切割出来的图片,上传到朋友圈,发现微信不按照我排列的序号来排版。这样的结果是很耗时间的。让我深思,能不能有一种,直接拼接成...

使用Python将图片转换为字符画并保存到文件

字符画(ASCII Art)是将图片转换为由字符组成的艺术作品。利用Python,我们可以轻松实现图片转字符画的功能。本教程将带你一步步实现这个功能,并详细解释每一步的代码和实现原理。环境准备首先,你...

Python实现图片格式转换

在日常生活和工作中经常遇到需要转换图片格式的情况,网上有很多图片转换工具,但都需要注册登录,还有的要收费,作为一个程序员怎么能花这冤枉钱,于是就想着自己开发一个可以转换图片格式的软件。界面设计虽然只是...