(last_url)
return latest_url
Download all SMBC comics released after the given URL.
Download all SMBC comics released after the given URL.
Download all SMBC comics released after the given URL .
def check_smbc(last_url):
    """Download all SMBC comics released after the given URL."""
    url = 'https://www.smbc-comics.com/'
    # Get latest comics actual name for comparison/update
    res = requests.get(url)
    res.raise_for_status()
    soup = bs4.BeautifulSoup(res.text, 'lxml')
    name_elem = soup.select('input[value]')
    home_url = name_elem[0].get('value')
    url_check = 'https://www.' + home_url[7:]
    latest_url = url_check

    if url_check == last_url:
        print('No new SMBC comics have been published since last check')
    else:
        while url != last_url:
            res = requests.get(url)
            res.raise_for_status()
            soup = bs4.BeautifulSoup(res.text, 'lxml')
            comic_elem = soup.select('#cc-comic')

            if comic_elem == []:
                print('Could not find comic image.')
            else:
                try:
                    comic_url = ('https://www.smbc-comics.com/'
                                 + comic_elem[0].get('src'))
                    print('Downloading image {}'.format(comic_url))
                    res = requests.get(comic_url)
                    res.raise_for_status()
                except requests.exceptions.MissingSchema:
                    prev_link = soup.select('a[rel="prev"]')[0]
                    url = prev_link
                    continue

                image = open(os.path.join('Web Comics', os.path.basename(comic_url)), 'wb')
                for chunk in res.iter_content(100000):
                    image.write(chunk)
                image.close()

                prev_link = soup.select('a[rel="prev"]')[0]
                url = prev_link.get('href')

    return latest_url
def check_smbc ( last_url ) : url = 'https://www.smbc-comics.com/' # Get latest comics actual name for comparison/update res = requests . get ( url ) res . raise_for_status ( ) soup = bs4 . BeautifulSoup ( res . text , 'lxml' ) name_elem = soup . select ( 'input[value]' ) home_url = name_elem [ 0 ] . get ( 'value' ) url_check = 'https://www.' + home_url [ 7 : ] latest_url = url_check if url_check == last_url : print ( 'No new SMBC comics have been published since last check' ) else : while url != last_url : res = requests . get ( url ) res . raise_for_status ( ) soup = bs4 . BeautifulSoup ( res . text , 'lxml' ) comic_elem = soup . select ( '#cc-comic' ) if comic_elem == [ ] : print ( 'Could not find comic image.' ) else : try : comic_url = ( 'https://www.smbc-comics.com/' + comic_elem [ 0 ] . get ( 'src' ) ) print ( 'Downloading image {}' . format ( comic_url ) ) res = requests . get ( comic_url ) res . raise_for_status ( ) except requests . exceptions . MissingSchema : prev_link = soup . select ( 'a[rel="prev"]' ) [ 0 ] url = prev_link continue image = open ( os . path . join ( 'Web Comics' , os . path . basename ( comic_url ) ) , 'wb' ) for chunk in res . iter_content ( 100000 ) : image . write ( chunk ) image . close ( ) prev_link = soup . select ( 'a[rel="prev"]' ) [ 0 ] url = prev_link . get ( 'href' ) return latest_url