zoukankan      html  css  js  c++  java
  • Python批量爬取唯美类图片

    效果图:

      

    实现代码:

    # -*- coding: UTF-8 -*-
    import requests
    import re
    
    urls = ['http://www.ik123.com/q/tuku/weimei/list_11_{}.html'.format(str(i)) for i in range(1, 201)]
    headers={
        'Referer': 'http://www.ik123.com/q/tuku/weimei/list_11_1.html',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.108 Safari/537.36'
    }
    
    def list_info(url):
        res = requests.get(url)
        res.encoding = 'GB2312'
        srcs = re.findall("<img style=' 190px; height: 130px' src='(.*?)' alt='.*?'/>", res.text, re.S)
        titles = re.findall("<img style=' 190px; height: 130px' src='.*?' alt='[<b>]?(.*?)[</b>]?'/>", res.text, re.S)
    
        for src, title in zip(srcs, titles):
            try:
                info = {
                    'src': src,
                    'title': title
                }
                print(info)
                pic=requests.get(info['src'],headers=headers)
                f=open('pic\'+str(info['title'])+'.jpg', 'wb')
                f.write(pic.content)
                f.close()
            except IndexError:
                pass
    
    if __name__ == '__main__':
        for url in urls:
            list_info(url)
  • 相关阅读:
    Azure SQL Storage
    T-SQL quries
    映射盘符
    繁体及其输入法、乱码问题
    匈牙利命名法
    C++四种转换总结
    windows系统下进程间通信
    Qt 中文字符串问题
    PDB文件详解
    DbgView 无法开启Capture Kernel问题
  • 原文地址:https://www.cnblogs.com/feiyucha/p/10845830.html
Copyright © 2011-2022 走看看