Python: Standard Library - Access the Internet

There are several means for accessing the internet and processing internet protocols. The simplest two for processing data received from urls urllib.request smtplib and for sending email:

from urllib.request import urlopen
for line in urlopen(‘http://tycho.usno.navy.mil/cgi-bin/timer.pl’):
… line = line.decode(‘utf-8’) # Decoding the binary data to text.
… if ‘EST’ in line or ‘EDT’ in line: # look for Eastern Time
… print(line)


Nov. 25, 9:43:32 PM EST

import smtplib
server = smtplib.SMTP(‘localhost’)
server.sendmail(‘[email protected]’, ‘[email protected]’,
… “”“To: [email protected]
… From: [email protected]

… Beware the Ides of March.
… “””)

server.quit()

Note that the second example needs to have a local mail server in a run.

Guess you like

Origin blog.csdn.net/weixin_44523387/article/details/92163761