• python 爬图片


    学了两天python,语法慢慢熟悉吧,数据结构都没写过。

    写了一个爬图片的小东西。挺有意思的。都是女神照 (✿◡‿◡)

    用的是正则表达式,

     1 '''
     2 符号:
     3     . 匹配任意字符,
    除外
     4     * 匹配前一个字符一次或无限次
     5     ? 匹配前一个字符0次或1次
     6     .*    贪心匹配
     7     .*?    非贪心匹配
     8     ()    返回括号内容
     9 方法:
    10     findall
    11     search
    12     sub
    13 
    14 用的最多的是(.*?)
    15 '''

    requests的导入,我也是醉了,还要easy_install,pip,

    后来一切准备就绪了,浏览器打开的源码http:/,都是这种鬼东西,我就用word替换,发现不行,太多的不可见字符,于是用记事本替换,最后还是最好的办法,我把chrome更新了。

     1 import re
     2 import requests
     3 
     4 f = open('html.txt','r')
     5 fileshtml = f.read()
     6 f.close()
     7 
     8 pic_url = re.findall('src2="(.*?)"',fileshtml,re.S)
     9 
    10 i = 0
    11 for each in pic_url:
    12 
    13     if each[0] == 'h':
    14         print each
    15         pic = requests.get(each)
    16         fp = open('pic\' + str(i) + '.jpg','wb')
    17         fp.write(pic.content)
    18         fp.close()
    19         i += 1
  • 相关阅读:
    NFS /etc/exports参数解释
    M3U8流视频数据爬虫
    Qt5之C++Widgets编程
    Qt Quick
    RabbitMQ 安装配置
    nginx和netty区别
    S锁和X锁
    关于Spring Cloud各种组件的停更/升级/替换
    3、无重复字符的最长子串
    Spring Cloud Alibaba Sentinel实现熔断与限流
  • 原文地址:https://www.cnblogs.com/TreeDream/p/6363479.html
Copyright © 2020-2023  润新知