<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    大漠駝鈴

    置身浩瀚的沙漠,方向最為重要,希望此blog能向大漠駝鈴一樣,給我方向和指引。
    Java,Php,Shell,Python,服務器運維,大數據,SEO, 網站開發、運維,云服務技術支持,IM服務供應商, FreeSwitch搭建,技術支持等. 技術討論QQ群:428622099
    隨筆 - 238, 文章 - 3, 評論 - 117, 引用 - 0
    數據加載中……

    Python Urllib2


    http://docs.python.org/library/urllib.html


    設置超時時間

         import socket

    import urllib2

    socket.setdefaulttimeout(seconds)

    open = urllib2.urlopen("

    過socket.setdefaulttimeout() 設置了全局默認超時時間,從而給urllibe2.urlopen()也設置了默認的超時時間





    抓取圖片(這個例子里的Request找不到,我一般只有urllib2)
    soup=urlllib2.open(url)

    # Let's create a function that downloads a file, and saves it locally.
    #
     This function accepts a file name, a read/write mode(binary or text),
    #
     and the base url.

    def stealStuff(file_name,file_mode,base_url):
        
    from urllib2 import Request, urlopen, URLError, HTTPError

        
    #create the url and the request
        url = base_url + file_name
        req 
    = Request(url)

        
    # Open the url
        try:
            f 
    = urlopen(req)
            
    print "downloading " + url

            
    # Open our local file for writing
            local_file = open(file_name, "w" + file_mode)
            
    #Write to our local file
            local_file.write(f.read())
            local_file.close()

        
    #handle errors
        except HTTPError, e:
            
    print "HTTP Error:",e.code , url
        
    except URLError, e:
            
    print "URL Error:",e.reason , url

    # Set the range of images to 1-50.It says 51 because the
    #
     range function never gets to the endpoint.
    image_range = range(1,51)

    # Iterate over image range
    for index in image_range:

        base_url 
    = 'http://www.techniqal.com/'
        
    #create file name based on known pattern
        file_name =  str(index) + ".jpg"
        
    # Now download the image. If these were text files,
        # or other ascii types, just pass an empty string
        # for the second param ala stealStuff(file_name,'',base_url)
        stealStuff(file_name,"b",base_url)

    posted on 2011-03-04 16:02 草原上的駱駝 閱讀(1174) 評論(0)  編輯  收藏 所屬分類: Python

    主站蜘蛛池模板: 狼友av永久网站免费观看| av永久免费网站在线观看| 黄页网站在线看免费| 67pao强力打造67194在线午夜亚洲| 在线人成免费视频69国产| 亚洲国产精品特色大片观看完整版| a一级爱做片免费| 国产精品亚洲综合一区| 香蕉免费在线视频| 亚洲av日韩av无码| 99视频有精品视频免费观看| 91久久亚洲国产成人精品性色| 1000部国产成人免费视频| 456亚洲人成影院在线观| 狠狠久久永久免费观看| 菠萝菠萝蜜在线免费视频| 久久精品国产亚洲精品| 免费人成在线观看视频高潮| 亚洲一区免费观看| 免费99精品国产自在现线| 亚洲精品无码永久在线观看男男| 国产精品深夜福利免费观看| 黄网站在线播放视频免费观看| 成人午夜亚洲精品无码网站| 日本人成在线视频免费播放| 亚洲国产精品综合久久网各| 免费高清资源黄网站在线观看 | 成熟女人特级毛片www免费| 色屁屁www影院免费观看视频| 久久精品国产亚洲沈樵| 国产成人免费高清激情明星| 国产天堂亚洲国产碰碰| 亚洲级αV无码毛片久久精品| 久久久久久免费视频| 猫咪免费观看人成网站在线| 亚洲Av无码专区国产乱码DVD| 性感美女视频免费网站午夜| h视频在线免费观看| 亚洲不卡在线观看| 亚洲无码黄色网址| 在人线av无码免费高潮喷水|