print('could not find comic image 'elsecomicurl 'https:comicelem[ get('src'download the image print('downloading image % (comicurl)res requests get(comicurlres raise_for_status(todosave the image to /xkcd todoget the prev button' url print('done 'from inspecting the xkcd home page with your developer toolsyou know that the element for the comic image is inside element with the id attribute set to comicso the selector '#comic imgwill get you the correct element from the beautifulsoup object few xkcd pages have special content that isn' simple image file that' fineyou'll just skip those if your selector doesn' find any elementsthen soup select('#comic img'will return blank list when that happensthe program can just print an error message and move on without downloading the image otherwisethe selector will return list containing one element you can get the src attribute from this element and pass it to requests get(to download the comic' image file step save the image and find the previous comic make your code look like the following#python downloadxkcd py downloads every single xkcd comic import requestsosbs --snip-save the image to /xkcd imagefile open(os path join('xkcd'os path basename(comicurl))'wb'for chunk in res iter_content( )imagefile write(chunkimagefile close(get the prev button' url prevlink soup select(' [rel="prev"]')[ url 'print('done 'web scraping