0

Very new to Python and struggling to get the hang of it, im needing to retrieve a webpage via its url, and return its contents. The contents will be parsed later to find hyperlinks etc using regular expressions. (Im not wanting to use beautifulsoup)

import urllib.request
url = "http://stackoverflow.com"
f = urllib.urlopen(url)
print (f.read())

I realise my answer is probably very wrong but any pointer in the right direction would be great.

Eric C
  • 1
  • 1
  • Either explicitly import `urlopen`, or use `f = urllib.request.urlopen(url)` – Oliver Baumann Nov 09 '17 at 23:34
  • 1
    Possible duplicate of [How can I read the contents of an URL with Python?](https://stackoverflow.com/questions/15138614/how-can-i-read-the-contents-of-an-url-with-python) – Maxim Nov 10 '17 at 10:14

1 Answers1

1

In python 3.6 urlopen is in urllib.request module.

from urllib.request import urlopen

url = "http://stackoverflow.com"
f = urlopen(url)
print (f.read())
domandinho
  • 1,260
  • 2
  • 16
  • 29