Skip to content

Instantly share code, notes, and snippets.

@pahaz
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pahaz/35ff9636cbd62bcdff51 to your computer and use it in GitHub Desktop.
Save pahaz/35ff9636cbd62bcdff51 to your computer and use it in GitHub Desktop.
from urllib.request import urlopen
from urllib.parse import quote, unquote
from urllib.error import URLError, HTTPError
def get_content(name):
"""
Возвращает содержимое вики-страницы или None (в случае ошибки).
"""
try:
with urlopen('http://ru.wikipedia.org/wiki/' + quote(name)) as page:
return page.readall().decode('utf-8')
except (URLError, HTTPError):
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment