Skip to content

Instantly share code, notes, and snippets.

@marcelo-reis
Last active October 28, 2020 21:09
Show Gist options
  • Save marcelo-reis/0e72f63eba11beb31a8b688a7942c39d to your computer and use it in GitHub Desktop.
Save marcelo-reis/0e72f63eba11beb31a8b688a7942c39d to your computer and use it in GitHub Desktop.
Python - A great way to start!
URL = 'https://pt.wikipedia.org/wiki/Programa_Ol%C3%A1_Mundo'
hw = ''
import urllib.request
try:
texto = urllib.request.urlopen(URL).read().decode('utf-8')
onde = texto.find('<title>')
except urllib.error.HTTPError:
print('Endereço Inválido')
except urllib.error.URLError:
print('Sem conexão')
else:
inicio = onde + 16
fim = inicio + 9
hwtxt = str(texto[inicio:fim])
separa = hwtxt.split()
hw = ', '.join(separa)
if hw == '':
hw = 'Olá, Mundo (Modo Offline)'
print(f'{hw}!')
@marcelo-reis
Copy link
Author

Varre a página 'Programa Olá Mundo' da Wikipedia e exibe na tela a mensagem 'Ola Mundo!'
Browse the 'Hello World Program' page on Wikipedia and display the message 'Hello World!'
Varle la página 'Programa Hola Mundo' de Wikipedia y muestra en pantalla el mensaje 'Ola Mundo!'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment