2

I get every day one specific email with a link in it. Then I klick the link which opens a browser, and then I save the webpage as a html file. That is what I have to do every day. Until now I do it manually, but I guess that it is a way to do it with python. I only know for now how to save an attachment from an email using python. But I don't know what to do with a link. Have somebody some experience with it?

Thanks in advance

Denis
  • 99
  • 10
  • Common StackOverFlow etiquette is to post what you have tried, what works, and what doesn't. Have you done any research of your own on this topic? What avenues have you pursued? Do you have a copy of the code you have tried to implement this functionality? – Ryan Bananahands Feb 11 '19 at 18:39
  • try [this](https://stackoverflow.com/a/62207356/1207193) – imbr Sep 23 '22 at 23:46

1 Answers1

2

You can do this with the requests package. Assuming you've already extracted the link as a string

link = 'https://...'

from requests import get
resp = get(link)
with open('todays-file.html', 'wb') as fOut:
    fOut.write(resp.content)

You will probably want to add handling if the link is bad (i.e. does not return a 20x status code), but that's the general idea.

Andrew F
  • 2,690
  • 1
  • 14
  • 25