python 爬取美女图片

liftword3个月前 (01-08)技术文章41
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自动化办公:一分钟高效搞定Excel所有图片的导入导出

在日常办公中,我们经常需要在Excel表格中插入或导出图片,特别是在制作产品目录、报告或展示数据时。现在有这样一份任务,产品名录表里需要将每个产品的实拍图片插入到D列上,产品有上百个,传统方法需要将图...

Python带你生成个性海报头像

利用Python语言,可以很方便帮你制作个性海报头像,无需插件,纯代码制作生成。一、生成文字型海报头像要生成一张关于Python基础语法的海报图片,你可以使用Python中的库如PIL(Pillow)...

如何在 Python 中从图像中提取表格

大约一年前,我的任务是从文档中提取和构建数据,主要包含在表格中。我没有计算机视觉方面的先验知识,很难找到合适的“即插即用”解决方案。可用的选项要么是基于神经网络 (NN) 的先进解决方案,这些解决方案...

告别Excel!如何用Python画一手漂亮的图表

为了进行必要的统计推断,可视化数据非常重要。经常用Excel的表哥表姐会喜欢里面的图形绘制,但告别Excel,我们用Python可以做到更漂亮更自动的图形。怎么来做呢?Python里有这个强大的武器。...