zoukankan      html  css  js  c++  java
  • 爬4k美女图片也很简单:

    import os
    import re
    import requests
    from urllib import request
    from bs4 import BeautifulSoup

    dirName = './美女图片'
    if not os.path.exists(dirName):
    os.mkdir(dirName)
    url = "http://pic.netbian.com/4kmeinv/index_{}.html"
    for page in range(6, 8):
    print("正在爬取第{}页数据:".format(page))
    new_url = url.format(page)
    response = requests.get(new_url)
    response.encoding = "gbk"
    soup = BeautifulSoup(response.text, "html.parser")
    div_obj = soup.find(name="div", attrs={"class": "slist"})
    li_list = div_obj.find_all(name="li")
    for li in li_list:
    img = li.find(name="img")
    img_src = img.get("src")
    new_img_src = "http://pic.netbian.com/" + img_src
    img_name = new_img_src.split('/')[-1]
    img_path = dirName + '/' + img_name # ./imgLibs/xxxx.jpg
    request.urlretrieve(new_img_src, filename=img_path)
    print(img_name, '下载成功!!!')

    效果:

     打包exe:

     

  • 相关阅读:
    [洛谷P2184]贪婪大陆
    [BJOI2006]狼抓兔子
    [JSOI2007]重要的城市(x)
    [NOIP2011提高组]Mayan游戏
    gitee 使用
    部分激光打印机清零方法
    django2.0内置分页
    django上下文处理器
    jquery键盘事件
    类视图装饰器
  • 原文地址:https://www.cnblogs.com/zhang-da/p/12307591.html
Copyright © 2011-2022 走看看