You love Mangas. You are searching for a way to read them offline. Congratulations, You just found a way.
We import the following packages
- requests - It gives us some of the functionality of the browser
- os - It lets us organize files
- bs4 - It would help us search the required HTML tag
Steps:
- We make a folder using os
- We use request to download the page
- We use bs4 to find the URL of imageFile
- We download the image using requests and write it
- We use bs4 to find next or previous image link and change URL accordingly.
1 | os.makedirs('xkcd',exist_ok=True) |
We make a new folder. If it already exists, no new folder is made.
1 | res=requests.get(url) |
We use requests to download the page.Second line stops executing program in the case of an error.
1 | soup=bs4.BeautifulSoup(res.text, "html.parser") |
We find Image URL
1 | imageFile=open(os.path.join('xkcd',comicElem[0].get('alt')),'wb') |
We save the image to the suitable folder path. We use os.path.join to get that path. Then we write the image.
The entire program for reference.
1 | import requests,os,bs4 |