This is what I have at the moment:
import bs4
import requests
def getXkcdComic(comicUrl):
for i in range(0,20):
res = requests.get(comicUrl + str(1882 - i))
res.raise_for_status()
soup = bs4.BeautifulSoup(res.text, 'html.parser')
img = soup.select_one("div#comic > img")
return str(img['src'])
link = getXkcdComic('https://xkcd.com/')
print(link)
I parses the html, gets one link, the first one, and since I know the url finishes at 1882 and the next I want is 1881, I wrote this for-loop
to get the rest.
It only prints one result as if there was not loop written.
Strangely, if I reduce the indentation for the return
function it returns a different url.
I didn't quite get how For-loops
works yet.
Also, this is my first post ever here so forgive my english and ignorance.