zoukankan      html  css  js  c++  java
  • python爬虫入门 爬图片的,用百度搜图,直接下,类型受限不过可以直接下,简单不少,下图片可以用

    import re
    import requests
    url = 'https://image.baidu.com/search/index?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fm=index&fr=&hs=0&xthttps=111111&sf=1&fmq=&pv=&ic=0&nc=1&z=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&ie=utf-8&word=%E5%B0%8F%E9%BB%84%E4%BA%BA&f=3&oq=xiaohuangren&rsp=0'
    html = requests.get(url).text
    pic_url = re.findall('"objURL":"(.*?)",',html,re.S)
    #match all the clauses,python regular expression for re
    i = 0
    for each in pic_url:
        print each
        try:
            pic = requests.get(each,timeout=10)
        except requests.exceptions.ConnectionError:
            print "error now for not loading the pictures"
            continue
        string = 'picture\'+str(i)+'.jpg'
        #str()--->conversion to string
        fp = open(string,'wb')
        #establish the file with the name of string,write ability and binary data
        fp.write(pic.content)
        fp.close()
        i+=1

  • 相关阅读:
    算法导论————KMP
    KMP算法
    几个很好的OJ网站
    查找(二分、hash、桶)
    动态规划
    贪心(未完待续)
    搜索的题
    codeVS 1031 质数环
    《将博客搬至CSDN》
    HDU1717小数化分数2
  • 原文地址:https://www.cnblogs.com/fenglongyu/p/7505153.html
Copyright © 2011-2022 走看看