zoukankan      html  css  js  c++  java
  • python-web-下载所有xkcd漫画

    下载所有xkcd漫画

     

    # downloads every single xkcd comic
    
    import requests,os,bs4
    url='http://xkcd.com'  # start url
    os.makedirs('xkcd',exist_ok=True) # store comics in ./xkcd
    while not url.endswith('#'):
        # todo:download the page 
        print('downloading page %s...'%url)
        res = requests.get(url)
        res.raise_for_status()
    
        soup = bs4.BeautifulSoup(res.text)
    
        # todo find the url of the comic image
        comicElem = soup.select('#comic img')
        if comicElem == []:
            print('could not find comic image')
        else:
            comicUrl = 'http:'+comicElem[0].get('src')
            # todo: download the iamge
            print('downloading image %s .... '%(comicUrl))
            res = requests.get(comicUrl)
            res.raise_for_status()
    
            # todo: save the image to ./xkcd
            imageFile = open(os.path.join('xkcd',os.path.basename(comicUrl)),'wb')
    
            for chunk in res.iter_content(100000):
                 imageFile.write(chunk)
            imageFile.close()
    
    
        # todo: get the prev button'url
        prevLink = soup.select('a[rel="prev"]')[0]
        url = 'http://xkcd.com'+prevLink.get('href')
  • 相关阅读:
    Android ANR 知多少
    电源管理
    功耗分析
    手机功耗测试
    Battery Historian
    Android 电量优化
    Android手机功耗
    功耗 Log 抓取要求规范
    Android 手机无法进入系统解决方案
    定屏死机问题操作指南
  • 原文地址:https://www.cnblogs.com/liu-wang/p/8997434.html
Copyright © 2011-2022 走看看